Java Enum Serialization / Deserialization with Jackson API

Jackson is the de-facto standard in the Java world for working with JSONs. JSON,  being the widely accepted and appreciated format for data transfer across different web services, most of the web service providers and consumers in the Java platform tend to use the Jackson API. Here are few of the use cases to serialize and deserialize Enums.

For analysis, the below object is used in all examples. The containing enums are defined as and when considered. @JsonInclude annotation used here simplifies the serialized JSON by ignoring the null values.

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class ObjectWithEnum
{
 private int someInteger = 100;
 private SimpleEnum simpleEnum;
 private WithIntField withIntField;
 private WithStringField withStringField;
 private WithMultiFields withMultiFields;
 private PrimaryColor primaryColor;
}

ObjectMapper, initialized as below is used in all examples:

ObjectMapper objectMapper = new ObjectMapper();

Continue reading “Java Enum Serialization / Deserialization with Jackson API”