How to Avoid Model Changes Nightmare in Java or Kotlin | by daleef rahman | Jan, 2022

Things you need to validate before deploying model changes to production

Dhalif ur-Rahman
Photo by Mohamed Rahmani on Unsplash

One common problem while parsing JSON data with Jackson is deserialization failure when JSON contains unknown properties. When you add a new property to an existing form class, make sure that the class is commented out with @JsonIgnoreProperties(ignoreUnknown = true).

userResponseJson = getJsonResponseFromUserService()
user = jacksonObjectMapper.readValue(userResponseJson, User.class);
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

This is the single most important thing to do before posting any form changes to production. This will help you reveal any mysterious bugs hiding in the dark.

New model category
Old JSON data

This point is for Kotlin, so Java users can skip it. In kotlin, if you are deserializing JSON with optional properties, make sure that those optional properties in your class are either null or have a default value. Otherwise, deserialization will be broken. However, in JAVA, this is not required, because JAVA sets unknown fields as null.

{  
"firstName": "Thor"
}
Instantiation of User value failed for JSON property lastName due to missing (therefore NULL..

Most companies have data repositories to enable and support business intelligence (BI) activities, especially analytics. Data from the primary database is usually destroyed into tables in the data warehouse and analytical reports are generated on top of these tables.

Different data exchange protocols and their object schemas de-serialize data differently. Understanding how your deserializer works, especially knowing the default value it sets is very important. Otherwise, you may experience unexpected behavior.

user = jacksonObjectMapper().readValue(json, User::class.java)

Automated tests are the wall of defense and the night clock that protects your blade from the attack of wild animals living outside.

Like it or not, paradigm changes are something software engineers have to do often, especially if you work for a fast-paced company.

Leave a Comment