Libraries such as GSON, Jackson, or the Java Persistence API (JPA) usually use the no-argument (default) constructor to create an object and set its fields through reflection. In newer versions of GSON, you no longer need to declare a default constructor, see here .
If you need to call a specific constructor in GSON, you can implement a custom JsonDeserializer
, as mentioned here .
In other libraries, such as Jackson, you can define deserialization of methods rather than fields (for example, GSON does ), which allows you to replace the missing constructor call.
source share