java
java copied to clipboard
Parsing embedded array field order gets messed up when decoding
For object with an array list of objects with more then one item in the array like {"a":[{"c":"12","d":12},{"c":"12","d":12}]} the following exception occurs. If the array is reduced to 1 length of one value it is successful, if it is mapped as Any[] it works as well. In the following case the nested object had a UUID field and a datetime field, and the order got swapped.
Exception in thread "main" java.lang.IllegalArgumentException: Can not set java.util.Date field Event.datetime to java.util.UUID
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.base/java.lang.reflect.Field.get(Field.java:418)
at com.jsoniter.ReflectionObjectDecoder.decodeBinding(ReflectionObjectDecoder.java:382)
at com.jsoniter.ReflectionObjectDecoder.access$700(ReflectionObjectDecoder.java:10)
at com.jsoniter.ReflectionObjectDecoder$OnlyField.decode_(ReflectionObjectDecoder.java:153)
at com.jsoniter.ReflectionObjectDecoder$OnlyField.decode(ReflectionObjectDecoder.java:119)
at com.jsoniter.ReflectionArrayDecoder.decode(ReflectionArrayDecoder.java:35)
at com.jsoniter.ReflectionObjectDecoder.decodeBinding(ReflectionObjectDecoder.java:376)
at com.jsoniter.ReflectionObjectDecoder.decodeBinding(ReflectionObjectDecoder.java:384)
at com.jsoniter.ReflectionObjectDecoder.access$700(ReflectionObjectDecoder.java:10)
at com.jsoniter.ReflectionObjectDecoder$OnlyField.decode_(ReflectionObjectDecoder.java:164)
at com.jsoniter.ReflectionObjectDecoder$OnlyField.decode(ReflectionObjectDecoder.java:119)
at com.jsoniter.JsonIterator.read(JsonIterator.java:385)
at com.jsoniter.JsonIterator.read(JsonIterator.java:375)
at com.jsoniter.JsonIterator.deserialize(JsonIterator.java:441)
at com.jsoniter.JsonIterator.deserialize(JsonIterator.java:404)
at happy.main(happy.java:55)