Fun with Jackson Serialization

Spending some quality time this weekend walking through the deeper layers of Jackson JSON serialization. I’ve used the library casually in the past, but never for anything of any great complexity. It has recently come up as a target for some more complicated (harder to map directly into JSON) data structures. I’m spending a few hours this weekend putting together some sample code to ring the changes on things I might want Jackson to do.

Initial sample code bits are just walking through the basics and making sure I remember what is needed there. I am noticing a few things:

  • It doesn’t care about serializable at all. I expect that it uses reflection to walk the object tree and find property accessors directly.
  • It demands getters and setters for all properties to be serialized. A constructor with the appropriate arguments is not an option. This means that immutable-ish objects are not supported. You must be able to read and write object properties individually to make Jackson work.
  • It does respect transient so it is easy enough to mark internal implementation details for exclusion from processing.
  • The object mapper does not like objects with more than one single argument setter, even if one setter exactly matches the type being loaded into the de-serialized object.

Next step is going to be creating a map of string to custom object.

So far I’ve done the easy stuff. Some evening soon I’ll try to find time to add in the more complicated bits. Code is here.

And now custom object that is a proper map key (implements hashCode and Equals) to custom object.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.