Posts

Showing posts from February, 2022

Google Auto Value with Jackson Json

 I got a chance to work on a code base which used Google's Auto Value library and Jackson library for serialising and deserialising Json request and response payload. I tried to get the sweet spot with minimal need of annotations from Auto Value and Jackson. The following example shows the bare minimal change need to generate Json payload. It has the flexibility to construct the value object using builder pattern and ability to handle optional fields, collections and change the field name if required. package com.harishkannarao.example; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.google.auto.value.AutoValue; import java.time.OffsetDateTime; import java.util.List; import java.util.Optional; import java.util.UUID; @AutoValue @JsonDeserialize(builder = AutoValue_ExampleModel.Builder.class) public abstract class ExampleModel {