NullPointerException

29 views
Skip to first unread message

arthur....@googlemail.com

unread,
Aug 20, 2013, 11:51:50 AM8/20/13
to jso...@googlegroups.com
Hi, I am using json-io to serialize/deserialize a class that I have no access to. It is a pretty complex class, since it can have primitive and complex/nested types in it. Also, its structure is determined at runtime.
Conversion from Java to JSON seems to work, but when I take the JSON String to convert it to an object, I get a NullPointerException:
Exception in thread "Thread-14" java.lang.NullPointerException
    at com.cedarsoftware.util.io.JsonReader.loadClass(JsonReader.java:2104)
    at com.cedarsoftware.util.io.JsonReader.classForName(JsonReader.java:2054)
    at com.cedarsoftware.util.io.JsonReader.createJavaObjectInstance(JsonReader.java:1365)
    at com.cedarsoftware.util.io.JsonReader.convertParsedMapsToJava(JsonReader.java:723)
    at com.cedarsoftware.util.io.JsonReader.readObject(JsonReader.java:688)
    at com.cedarsoftware.util.io.JsonReader.jsonToJava(JsonReader.java:600)

Any ides?

arthur....@googlemail.com

unread,
Aug 20, 2013, 11:55:25 AM8/20/13
to jso...@googlegroups.com
This is the String:

{"@type":"com.rti.dds.dynamicdata.DynamicData","_typeCode":{"_kind":{"_ordinal":10,"_name":"TK_STRUCT"},"_name":"Addition","_isPointer":false,"_typeModifier":0,"_typeCode":{"_kind":{"_ordinal":0,"_name":"TK_NULL"},"_name":null,"_isPointer":false,"_typeModifier":0,"_typeCode":null,"_maximumLength":0,"_default_index":0,"_dimensions":null,"_extensibilityKind":{"@id":7,"_ordinal":0,"_name":"FINAL_EXTENSIBILITY"},"_structMembers":null,"_unionMembers":null,"_enumMembers":null,"_valueMembers":null,"_sparseMembers":null,"_nativeTypeCode":0,"_nativeTypeObject":0,"lockTypeCode":false},"_maximumLength":0,"_default_index":-1,"_dimensions":null,"_extensibilityKind":{"_ordinal":1,"_name":"EXTENSIBLE_EXTENSIBILITY"},"_structMembers":[{"name":"value1","type":{"@id":6,"_kind":{"_ordinal":1,"_name":"TK_SHORT"},"_name":null,"_isPointer":false,"_typeModifier":0,"_typeCode":null,"_maximumLength":0,"_default_index":0,"_dimensions":null,"_extensibilityKind":{"@ref":7},"_structMembers":null,"_unionMembers":null,"_enumMembers":null,"_valueMembers":null,"_sparseMembers":null,"_nativeTypeCode":0,"_nativeTypeObject":0,"lockTypeCode":false},"is_pointer":false,"bits":-1,"is_key":false},{"name":"value2","type":{"@ref":6},"is_pointer":false,"bits":-1,"is_key":false}],"_unionMembers":null,"_enumMembers":null,"_valueMembers":null,"_sparseMembers":null,"_nativeTypeCode":0,"_nativeTypeObject":0,"lockTypeCode":false},"native_dynamic_data":1805663544,"_created_by_factory":true,"native_dynamic_data_info":1805663480,"native_dynamic_data_member_info":1805661952,"_actualLength":[0]}

John DeRegnaucourt

unread,
Aug 20, 2013, 7:48:01 PM8/20/13
to jso...@googlegroups.com
The issue you are likely running into is that one of the classes (DynamicData?) is not able to be instantiated.  Json-io gives a good effort at getting classes instantiated, however, it cannot always do it.  It tries every constructor on the class (public or private) until it can instantiate the object with no exceptions.  In your case, it tried them all and still failed.

You need to add an empty constructor (can be private) to the class (likely DynamicData) that is failing to construct. 

Best regards,
John



--
You received this message because you are subscribed to the Google Groups "json-io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-io+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages