#1102·gson

Support for java.util.Optional

Author: prdoyleCreated Jun 14, 2017Updated Aug 7, 2026
Labelsenhancementjava8

Usually, when I use Gson, I need to add special logic so that a field of `Optional<X>` gets serialized as `X` if it's present, and gets omitted if it's empty; and conversely on deserialization. This seems like the only reasonable way to handle `Optional`. Would you consider offering this feature (or accepting a PR that implements it)?