{"id":2403,"date":"2019-02-09T13:25:06","date_gmt":"2019-02-09T18:25:06","guid":{"rendered":"http:\/\/ninecrows.com\/career\/?p=2403"},"modified":"2019-02-11T12:40:38","modified_gmt":"2019-02-11T17:40:38","slug":"fun-with-jackson-serialization","status":"publish","type":"post","link":"https:\/\/ninecrows.com\/career\/2019\/02\/09\/fun-with-jackson-serialization\/","title":{"rendered":"Fun with Jackson Serialization"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Spending some quality time this weekend walking through the deeper layers of <a href=\"https:\/\/github.com\/FasterXML\/jackson\/wiki\/Jackson-Release-2.9\">Jackson JSON serialization<\/a>. I&#8217;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&#8217;m spending a few hours this weekend putting together some sample code to ring the changes on things I might want Jackson to do.<\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It doesn&#8217;t care about serializable at all. I expect that it uses reflection to walk the object tree and find property accessors directly.<\/li><li>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.<\/li><li>It does respect transient so it is easy enough to mark internal implementation details for exclusion from processing.<\/li><li>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.<\/li><\/ul>\n\n\n\n<p>Next step is going to be creating a map of string to custom object.<\/p>\n\n\n\n<p>So far I&#8217;ve done the easy stuff. Some evening soon I&#8217;ll try to find time to add in the more complicated bits. Code is <a href=\"https:\/\/github.com\/ninecrows\/SampleSerialize\">here<\/a>.<\/p>\n\n\n\n<p>And now custom object that is a proper map key (implements hashCode and Equals) to custom object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spending some quality time this weekend walking through the deeper layers of Jackson JSON serialization. I&#8217;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&#8217;m spending a few &hellip; <a href=\"https:\/\/ninecrows.com\/career\/2019\/02\/09\/fun-with-jackson-serialization\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Fun with Jackson Serialization<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[69],"tags":[],"class_list":["post-2403","post","type-post","status-publish","format-standard","hentry","category-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7F2Qc-CL","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/2403"}],"collection":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/comments?post=2403"}],"version-history":[{"count":5,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/2403\/revisions"}],"predecessor-version":[{"id":2412,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/2403\/revisions\/2412"}],"wp:attachment":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/media?parent=2403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/categories?post=2403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/tags?post=2403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}