Support for java.util.Optional
See original GitHub issueUsually, 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)?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Optional (Java Platform SE 8 ) - Oracle Help Center
This is a value-based class; use of identity-sensitive operations (including reference equality ( == ), identity hash code, or synchronization) on instances of ......
Read more >Guide To Java 8 Optional | Baeldung
In this tutorial, we're going to show the Optional class that was introduced in Java 8. The purpose of the class is to...
Read more >Java 8 Optional Class - GeeksforGeeks
util package. It can help in writing a neat code without using too many null checks. By using Optional, we can specify alternate...
Read more >Java 8 - Optional Class - Tutorialspoint
Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as...
Read more >Understanding, Accepting and Leveraging Optional in Java
Optional is a simple yet very significant addition in Java 8. See examples of how it can be useful both on its own,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Gson can’t depend on Java 8 types as it supports down to Java 6.
@kaqqao gson-java8-datatype worked great, but sadly it broke with Java 16 and isn’t maintained anymore (the linked repository is archived).
Java 6 as reached end of life 8(!) years ago, and Java 8 (and thus, Optional) exist for 7 years now. I think it’s about time to move on.