google-code-export / jsonplugin

Automatically exported from code.google.com/p/jsonplugin
1 stars 0 forks source link

Support wrapper class types for properties #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The JSON Interceptor can't set properties with wrapper class types (such as
java.lang.Long) because they don't return true for "isPrimitive()" (and
apparently autoboxing doesn't work with reflection?)

I started off with a simple patch, but when I went to implement tests for
it, I became uncomfortable with the amount of detail in the Interceptor
class, so I factored out a "JSONPopulator" class to which the
JSONInterceptor delegates.  There's also a kind of annoying amount of
chained-if/then/else logic in handling all eight wrapper class types, but
it passes the tests, so if someone wants to make that more elegant, I'll
defer that for later...

Also, I was not too excited about the instance field of DateFormat, because
SimpleDateFormat is known to not be threadsafe.  I factored that out into a
String property of the JSONPopulator which is used to instantiate a
formatter each time it is needed, but I couldn't see anywhere that the
JSONInterceptor's formatter property is actually set.  It could be added
back in as a string property and tidied up if someone is using a
non-standard date format.

I hope this isn't too far out of line, since I haven't been participating
too much in other development, but I am finding the JSONPlugin handy, and
more so if this patch can be accepted!

Original issue reported on code.google.com by joegermu...@gmail.com on 15 Oct 2007 at 10:29

Attachments:

GoogleCodeExporter commented 9 years ago
whoops. looks like I submitted without attaching the patch!

Original comment by joegermu...@gmail.com on 15 Oct 2007 at 10:30

Attachments:

GoogleCodeExporter commented 9 years ago
I think that the JSONPopulator was not included in the patch because it isn't 
under
SVN control, so here it is, along with a test class and a resource used for the 
test
class

Original comment by joegermu...@gmail.com on 1 Nov 2007 at 6:27

Attachments:

GoogleCodeExporter commented 9 years ago
whoops, one more class needed for testing

Original comment by joegermu...@gmail.com on 1 Nov 2007 at 6:28

Attachments:

GoogleCodeExporter commented 9 years ago
thanks for the patch!

Original comment by musa...@gmail.com on 2 Nov 2007 at 1:17