BigVertiser Ads

Wednesday, March 27, 2013

JSONer

JSONer, is a one of my ART(Annotated Reflective Tool) projects. It extends a basic generic infrastructure, to allow JAVA instance custom serialization of any sort.

This project supports the serialization, and deserialization of Java instances to and from JSON text respectively.


  • JSONer is very simple to implement, it requires the jar in your project build path, and to annotate your JSON bean class with a JSON_Class annotation. Furthermore any member which needs to be serialized, or deserialized, MUST be annotated with a JSON_Field annotation.
  • Adding a new parser type is simpler then any other parser... you simply extend the JSON_TypeParser<YourType> specify your type, implement your serialization and deserialization, and specify the parser class type in the annotation of the specific field.
  • Adding support for generic type is also simpler then any other parser any List<?> or Map<?,?> first generation generic types, if to be more specific List<List<Item>> is not supported, while List<AnyItem> is supported, and in order to solve this sort of issue, wrap your List<Item> and turn it into AnyItem. (and don't forget to annotate the class type and member...)
    (I must extend that unlike my ReXML, this implementation only works for the specified type. if inherited type are stored in the list, they would be down parsed(casted) to the parent class type defined in the annotation!!)
  • Don't worry about nested JSON_Class types, if the class type of a members are annotated correctly, the parser would handle it.
  • You may also configure whether a member is optional, and use the same object for deserializing multiple different texts.
The only thing I didn't (want to get into) implement is a recursive handling... it will be a pain in the S!