question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for java.util.Optional

See original GitHub issue

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)?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
JakeWhartoncommented, Jun 14, 2017

Gson can’t depend on Java 8 types as it supports down to Java 6.

6reactions
piegamesdecommented, Jul 10, 2021

@kaqqao gson-java8-datatype worked great, but sadly it broke with Java 16 and isn’t maintained anymore (the linked repository is archived).

Gson can’t depend on Java 8 types as it supports down to Java 6.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found