klaxon icon indicating copy to clipboard operation
klaxon copied to clipboard

nextObject() crashed when encountering inner objects

Open Kaijiro opened this issue 5 years ago • 1 comments

Hello !

First of all thank you for the great work ! I ran on something strange, let me know if this is actually a bug or a misusage of the library. This is a sample of Json with an inner object :

{
     "name" : "Joe",
     "obj1" : { "a" : 1, "b" : 2, "c": { "d": 4 } }
}

When running this sample of code below, an exception will raise :

JsonReader(StringReader(json)).use {reader ->
    reader.beginObject {
        while(reader.hasNext()){
            when(reader.nextName()){
                "obj1" -> {
                    println("Obj1")
                    println(reader.nextObject().toJsonString(true))
                    println("End obj")
                }
                else -> println(reader.nextName())
            }
        }
    }
}
Exception in thread "main" com.beust.klaxon.KlaxonException: Expected a value but got {

When removing the c property, everything works fine but I need it in my Json .... Any suggestion ?

Kaijiro avatar Apr 23 '19 23:04 Kaijiro

Hi I got the same, but with an array value.

There is a work around here https://stackoverflow.com/questions/48272725/klaxon-expected-a-name-but-got-left-brace

Author answer is also there, but not obvious to me.

alihabib80 avatar Nov 03 '20 05:11 alihabib80