Languages
[Edit]
EN

Java FIX for java.io.Not Serializable Exception: java.util.Optional

13 points
Created by:
Payne
654

1. Problem description

Edit

How to solve java util Optional serializable exception?

Full stack trace:

Here is my code which explains what I've tried so far

Below code tries to serialize field Optional age

As the result we get:

My code to get this exception:

2. Solution with java Optional

Edit

Solution no 1 to this problem is just do not use optional as field value

Instead use it as return type from the getter method
eg:

Entire code which solves your problem:

3. Solution with Guava - Serializable Optional

Edit

Guava internally

References

Edit
  1. Optional - Java docs
  2. Serializable Optional - Guava docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join