79340560

Date: 2025-01-08 19:41:23
Score: 2.5
Natty:
Report link

You should provide a no argument constructor for the class with the default values you desire Gson to populate when there is a missing field, it only works that way.

Source: https://github.com/google/gson/blob/main/UserGuide.md#custom-serialization-and-deserialization

The other choice is to define an instance creator so Gson can use it to populate the missing fields. See here: https://github.com/google/gson/blob/main/UserGuide.md#writing-an-instance-creator

Reasons:
  • Probably link only (1):
  • Low length (0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: AAA