Thu. Mar 28th, 2024
Jackson configuration

Jackson, one of my favorite tools to use for Java POJO to/from JSON, has a number of configuration settings.  Today I am going to discuss a few of these settings and why I recommend the ones that I do.

Serialization Features

Serialization is the conversion of Java POJO’s to JSON.  These feature control, how that conversion is handled.  


SerializationFeature.WRITE_NULL_MAP_VALUES

If you are passing your JSON over the network, then I recommend setting this value to FALSE.  However, if you are not sending your JSON over the network, then I would leave this feature as TRUE.

Disabling this will save you bytes in the data transfer.  While the bytes used for the name of the field, may not be many, consider when it’s part of an array, multiple that out.  Over time it can be a significant number of bytes that can be saved.

Start with this setting on from the beginning and develop your application with this setting.  This will ensure all of your code supports this.  Trying to enable this in the middle of development can mean a considerable chunk of time making modifications to support missing fields.

SerializationFeature.WRITE_DATES_AS_TIMESTAMPS

Set this to FALSE to allow dates to be passed as human-readable string.  This will greatly improve debugging processes.  However, if this data is going across in a data transfer, it is costing you bytes.  For development have this set to FALSE, for production, change this back to TRUE, and reduce the data transfer size.

SerializationFeature.
WRITE_ENUMS_USING_INDEX

This is a development decision, and the role your ENUMs are going to play.  If the text of your enum is what you need then set this to FALSE.  However, if bytes count, set this to TRUE, as an ordinal number will be smaller in bytes than the textual representation.


Deserialization Features

Deserialization is the conversion of JSON to POJO’s.

DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES

Always a good one to set to FALSE.  Prevent Jackson from throwing an exception if an additional field is found in the JSON. This way the JSON can be updated and ready to make use of a new field prior to POJO if necessary.  This will help encapsulate your work allowing for things to be added in slowly.

By Jeffery Miller

I am known for being able to quickly decipher difficult problems to assist development teams in producing a solution. I have been called upon to be the Team Lead for multiple large-scale projects. I have a keen interest in learning new technologies, always ready for a new challenge.

Leave a Reply

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

%d