Parsing to data class with many values gives random result
See original GitHub issueFound sooo strange behaviour. I have data class with ~100 values in it. When I’m parsing a string (json.parse(class.serializer(), someString)
) or string -> JsonArray -> JsonElement -> data class (json.fromJson(class.serializer(), jsonElement
)) values in data class are filled randomly. Some of them located on their places but some of them missing. So, take a look at the code:
val s = """{"value10":"Anything","value11":3456.7,"value33":"SomeString","value26":0.123,"value38":"2019-02-15T07:58:41.519Z"}"""
println("SHOULD BE THIS: $s")
println("BUT GOT THIS: " + json.parse(Testing.serializer(), s))
@Serializable
data class Testing (
@Optional
val value1: String? = null,
@Optional
val value2: String? = null,
@Optional
val value3: String? = null,
@Optional
val value4: String? = null,
@Optional
val value5: String? = null,
@Optional
val value6: Double? = null,
@Optional
val value7: Double? = null,
@Optional
val value8: Double? = null,
@Optional
val value9: Double? = null,
@Optional
val value10: String? = null,
@Optional
val value11: Double? = null,
@Optional
val value12: Double? = null,
@Optional
val value13: Double? = null,
@Optional
val value14: Boolean = false,
@Optional
val value15: Boolean = false,
@Optional
val value16: Double? = null,
@Optional
val value17: Double? = null,
@Optional
val value18: Double? = null,
@Optional
val value19: Double? = null,
@Optional
val value20: Double? = null,
@Optional
val value21: Double? = null,
@Optional
val value22: Double? = null,
@Optional
val value23: Long? = null,
@Optional
val value24: Long? = null,
@Optional
val value25: Long? = null,
@Optional
val value26: Double? = null,
@Optional
val value27: Double? = null,
@Optional
val value28: Double? = null,
@Optional
val value29: Double? = null,
@Optional
val value30: Double? = null,
@Optional
val value31: Double? = null,
@Optional
val value32: Double? = null,
@Optional
val value33: String? = null,
@Optional
val value34: Double? = null,
@Optional
val value35: Double? = null,
@Optional
val value36: Double? = null,
@Optional
val value37: Double? = null,
@Optional
val value38: String? = null)
SHOULD BE THIS: {"value10":"Anything","value11":3456.7,"value33":"SomeString","value26":0.123,"value38":"2019-02-15T07:58:41.519Z"}
BUT GOT THIS: Testing(value1=null, value2=null, value3=null, value4=null, value5=null, value6=null, value7=null, value8=null, value9=null, value10=Anything, value11=3456.7, value12=null, value13=null, value14=false, value15=false, value16=null, value17=null, value18=null, value19=null, value20=null, value21=null, value22=null, value23=null, value24=null, value25=null, value26=0.123, value27=null, value28=null, value29=null, value30=null, value31=null, value32=null, value33=null, value34=null, value35=null, value36=null, value37=null, value38=null)
Now look at value33 and value38. They are null but shouldn’t be. Other values on their places. So it happens really randomly. In my situation application retrieves data via web socket and some values are present right now but in next second other values will be present. And some values after parsing are missing. Its not the same every time. Is it a bug? Or feature?😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (6 by maintainers)
Top Results From Across the Web
c# - Extra-Random JSON Parsing - Stack Overflow
Basically, it allows you to step through each JSON node 1 by 1 and you decide where to parse the value (put it...
Read more >Data Classes in Python 3.7+ (Guide)
In this tutorial, you will learn exactly which conveniences data classes provide. In addition to nice representations and comparisons, you'll see: How to...
Read more >Python | Generate random numbers within a given range and ...
Method 1: Generate random integers using random.randrange() method. Python provides a function named randrange() in the random package that can ...
Read more >Random Class (System) - Microsoft Learn
This can be useful for creating a test suite that processes random values, or for replaying games that derive their data from random...
Read more >Create Random Points (Data Management)—ArcGIS Pro
The Number of Points parameter can be specified as a number or as a numeric field in the constraining feature class containing values...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed with #164 in 1.3.30
I’m having the same issue, it would help tremendously if this could be fixed soon ! Is there any workaround in the meantime ? Thanks a lot