Below given APIs can be used to convert a Java object into JSON:
1. GSON: It is an open-source Java library which is used to serialize and deserialize Java objects to JSON.
2. Jackson API
Employee.java Pojo class
Default Serialization using Gson
See the code below for the default serialization using Gson Library.
Custom Serialization using Gson
We can change the default serialization by registering Type adapter for the Particular Pojo (for which serialization behavior needs to be changed). See the code below.
In the above custom serializer, we are adding salutation with the name on the basis of gender.