actolap / json-io

Automatically exported from code.google.com/p/json-io
0 stars 0 forks source link

Access to JsonObject.target required in custom JsonClassReaders #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I was not able to get a custom JsonClassReader for a non-primitive to work 
without accessing JsonObject.target. I always got unresolved references. In all 
built-in Readers the result is not just returned, but always also set to 
JsonObject.target. After doing this in my Reader it worked.

Do i miss something or is this an oversight?

Original issue reported on code.google.com by jkopc...@googlemail.com on 4 Jul 2013 at 8:26

GoogleCodeExporter commented 9 years ago
The target needs to be set (as you eventually did).  The .target is used so 
that when the read in JSON is converted to Java classes, this is the 'peer' 
Java class that will be the recipient of the values from the JsonObject (Map).  
Without a target, there is no peer Java object to copy the values to.

I did add a public get/setTarget() APIs To JsonObject so that the value can be 
fetched more easily (from outside the json-io packages).  The next release will 
have this easier access to the .target.  In the meantime, either use 
.setAccessible(true) and 'hack' your way to assigning the field, or change the 
source.

Original comment by jdereg@gmail.com on 17 Jul 2013 at 9:56