RichardHightower/boon — pull request #184 by mstipanov (2014-05-28 21:02:23+00:00)
Title: Fixed array property deserialization

Hi.

I noticed an error when deserializing JSON if using array as a property type. If I use fields, everything works.

Error:
/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13 EAP.app/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 13 EAP.app/lib/idea_rt.jar:/Applications/IntelliJ IDEA 13 EAP.app/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/mstipanov/Projekti/infobip-api-management/boon/target/test-classes:/Users/mstipanov/Projekti/infobip-api-management/boon/target/classes:/Users/mstipanov/.m2/repository/junit/junit/4.10/junit-4.10.jar:/Users/mstipanov/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 org.boon.json.JsonArrayPropertyTest

org.boon.Exceptions$SoftenedException: fieldName fields of class class org.boon.json.JsonArrayPropertyTest$ApiDynamicType had issues for value LIST for field FieldInfo [name=fields, type=class [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;, parentType=class org.boon.json.JsonArrayPropertyTest$ApiDynamicType]

CAUSE org.boon.Exceptions$SoftenedException :: An unexpected error has occurred
This is likely a programming error!
Object is [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;@48bfba23, index is 0, and set is java.lang.Object@23557525
The object is an array? true
The object is of type [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;
The set is of type java.lang.Object

CAUSE java.lang.IllegalArgumentException :: array element type mismatch
MESSAGE: fieldName fields of class class org.boon.json.JsonArrayPropertyTest$ApiDynamicType had issues for value LIST for field FieldInfo [name=fields, type=class [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;, parentType=class org.boon.json.JsonArrayPropertyTest$ApiDynamicType]

CAUSE org.boon.Exceptions$SoftenedException :: An unexpected error has occurred
This is likely a programming error!
Object is [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;@48bfba23, index is 0, and set is java.lang.Object@23557525
The object is an array? true
The object is of type [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;
The set is of type java.lang.Object

CAUSE java.lang.IllegalArgumentException :: array element type mismatch
ROOT CAUSE MESSAGE: array element type mismatch
This happens around this area in your code.
org.boon.core.reflection.Mapper.fromValueMap(Mapper.java:1154)
org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208)
org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200)
org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67)
org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278)
org.boon.json.JsonArrayPropertyTest.test_arrayProperty(JsonArrayPropertyTest.java:23)

Caused by: message: array element type mismatch type java.lang.IllegalArgumentException
java.lang.reflect.Array.set(Native Method)
org.boon.core.reflection.BeanUtils.idx(BeanUtils.java:1557)
org.boon.core.Conversions.toPrimitiveArrayIfPossible(Conversions.java:915)
org.boon.core.Conversions.coerce(Conversions.java:494)
org.boon.core.reflection.fields.BaseField.setValue(BaseField.java:511)
org.boon.core.reflection.Mapper.handleCollectionOfValues(Mapper.java:1032)
org.boon.core.reflection.Mapper.fromValueMapHandleValueCase(Mapper.java:1287)
org.boon.core.reflection.Mapper.fromValueMap(Mapper.java:1149)
org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208)
org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200)
org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67)
org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278)
org.boon.json.JsonArrayPropertyTest.test_arrayProperty(JsonArrayPropertyTest.java:23)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
org.junit.runners.ParentRunner.run(ParentRunner.java:300)
org.junit.runner.JUnitCore.run(JUnitCore.java:157)
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

--------------------------------------------------
--------------------------------------------------
org.boon.Exceptions$SoftenedException: fieldName fields of class class org.boon.json.JsonArrayPropertyTest$ApiDynamicType had issues for value LIST for field FieldInfo [name=fields, type=class [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;, parentType=class org.boon.json.JsonArrayPropertyTest$ApiDynamicType]

CAUSE org.boon.Exceptions$SoftenedException :: An unexpected error has occurred
This is likely a programming error!
Object is [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;@48bfba23, index is 0, and set is java.lang.Object@23557525
The object is an array? true
The object is of type [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;
The set is of type java.lang.Object

CAUSE java.lang.IllegalArgumentException :: array element type mismatch
at org.boon.Exceptions.handle(Exceptions.java:128)
at org.boon.core.reflection.Mapper.fromValueMap(Mapper.java:1154)
at org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208)
at org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200)
at org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67)
at org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278)
at org.boon.json.JsonArrayPropertyTest.test_arrayProperty(JsonArrayPropertyTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.boon.Exceptions$SoftenedException: An unexpected error has occurred
This is likely a programming error!
Object is [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;@48bfba23, index is 0, and set is java.lang.Object@23557525
The object is an array? true
The object is of type [Lorg.boon.json.JsonArrayPropertyTest$ApiDynamicTypeField;
The set is of type java.lang.Object

CAUSE java.lang.IllegalArgumentException :: array element type mismatch
at org.boon.Exceptions.handle(Exceptions.java:164)
at org.boon.core.reflection.BeanUtils.idx(BeanUtils.java:1572)
at org.boon.core.Conversions.toPrimitiveArrayIfPossible(Conversions.java:915)
at org.boon.core.Conversions.coerce(Conversions.java:494)
at org.boon.core.reflection.fields.BaseField.setValue(BaseField.java:511)
at org.boon.core.reflection.Mapper.handleCollectionOfValues(Mapper.java:1032)
at org.boon.core.reflection.Mapper.fromValueMapHandleValueCase(Mapper.java:1287)
at org.boon.core.reflection.Mapper.fromValueMap(Mapper.java:1149)
... 32 more
Caused by: java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at org.boon.core.reflection.BeanUtils.idx(BeanUtils.java:1557)
... 38 more

--------------------------------------------------

Process finished with exit code 255