Skip to content

An example of using Java 8's Optional with Morphia and Jackson model serialization

Notifications You must be signed in to change notification settings

denniskuczynski/morphia_jackson_java8_optional_example

Repository files navigation

Morphia/Jackson Java 8 Optional Example

Morphia (mongoDB) and Jackson (JSON) serialization can both be leveraged to serialize/deserialize the new Java 8 Optional type.

For Jackson, you simply need to register the JDK8 module. https://github.com/FasterXML/jackson-datatype-jdk8

For Morphia, you need to register a custom converter for Optional. OptionalConverter

Tips

  • The raw data may still contain nulls or empty fields, so default values should be specified on the Java models for non-optional fields.

Running the example

  • mvn compile
  • mvn exec:java -Dexec.mainClass="morphia_jackson_java8_optional.Example"

About

An example of using Java 8's Optional with Morphia and Jackson model serialization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages