Domain Model and Test Data
Let’s create a domain model for a Customerwith some contact data: Note that all fields will be mandatory, except for phoneNumber and email Json Data Size with Jackson Default Options
Let’s write a Java object to JSON with the default Jackson options: Let’s see the mock data for the first Customer: When using default Jackon options Compressing with gzip
As text data, JSON data compresses nicely. That’s why gzip is our first option to reduce the JSON data size. Moreover Shorter Field Names in Json
It’s a best practice to use field names that are neither too short nor too long Serializing to An Array
Let’s see how we can further reduce the JSON data size by leaving out the field names altogether Excluding Null Values
Jackson and other JSON processing libraries may not handle JSON null values correctly when reading or writing JSON. For example New Domain Class
We achieved the smallest JSON data size so far by serializing it to an array. One way of reducing that even further is a new domain model with fewer fields Conclusion
In this article, we first saw why we need to reduce JSON data sizes. Next, we learned various ways to reduce this JSON data size. Finally