0

I am using Lagom framework with Java. I have a model class which uses optional in the constructor argument. I have only one persistent entity based on this model class and have entity tests (using PersistentEntityTestDriver) for this entity. The problem is all entity tests fail with this error -

java.lang.AssertionError:

Expected :[]

Actual :[[class java.util.Optional is not serializable, No configured serialization-bindings for class [com.sp.User]]

Sample User class -

class User {

    public final UUID id;
    public final ZonedDateTime date;

    @JsonCreator
    public User(@JsonProperty("id") UUID userId,
                @JsonProperty("address") Optional<ZonedDateTime> date) {
        this.id = id;
        this.date = createdOn.orElse(getUtcDateTime());
    }

}

How can I configure my service to serialize optional.

Darshan Patel
  • 2,839
  • 2
  • 25
  • 38
konghoho
  • 53
  • 6
  • serialize is not meant by the service – Roman C Nov 11 '17 at 03:55
  • I solved it by implementing the model class with Jsonable interface (com.lightbend.lagom.serialization.Jsonable). Implementing this interface means giving it higher priority than the default java Serializable interface. So, akka will use its own serializer for Optional rather than using default java serialization. Doc - (https://www.lagomframework.com/documentation/1.0.x/java/api/index.html?com/lightbend/lagom/serialization/Jsonable.html) – konghoho Nov 14 '17 at 19:37

1 Answers1

0

What version of Jackson are you using? I think you need at least 2.8.5 which added a serializer for Optional class.

dkatzel
  • 31,188
  • 3
  • 63
  • 67