Hi, i am trying to integrate Vavr with Lagom.
The only problem i am facing, is serializing the types provided by the library using lagom ObjectMapper.
I have been trying to register the Vavr jackson module _GitHub - vavr-io/vavr-jackson: Jackson datatype module for Vavr with Lagom, by applying the steps described in this pages:
- Lagom Java 1.4.x Serialization
- Customise Jackson ObjectMapper in Lagom
- Using vavr with Play Framework _Using vavr with Play Framework
If i add this line to application.conf:
lagom.serialization.json.jackson-modules += io.vavr.jackson.datatype.VavrModule
Only part of the types are successfully serialized. Lagom fails in serializing the types:
- io.vavr.collection.List
- …?
And the types that are successfully serialized have weird json structures.
The type io.vavr.control.Option is serialized it this structure:
Option<String> name = Option.of("wht?"); { "name": { "empty": false, "async": false, "singleValued": true, "lazy": false, "defined": true, "orNull": "wht?" } }
When it should serialize in the same way as scala.Option
Option<String> name = Option.of("ok") { "name": "ok" } Option<String> name = Option.none {}
I have also tryed to register the Vavr jackson module directly on the ObjectMapper.
The results were the same.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.vavr.jackson.datatype.VavrModule;
public class CustomJacksonModule extends SimpleModule {
@Override
public void setupModule(SetupContext setupContext) {
ObjectMapper mapper = setupContext.getOwner();
mapper.registerModule(new VavrModule());
}
}
-------------------------------------------------------------------------------------------------------------------------------------
import com.google.inject.AbstractModule;
import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport;
import util.CustomJacksonModule;
public class AppModule extends AbstractModule implements ServiceGuiceSupport {
@Override
protected void configure() {
bind(CustomJacksonModule.class).asEagerSingleton();
bindService(BlueService.class, BlueServiceImpl.class);
}
}
-------------------------------------------------------------------------------------------------------------------------------------
// ??? play.modules.disabled += play.core.ObjectMapperModule
// ??? lagom.serialization.json.jackson-modules += io.vavr.jackson.datatype.VavrModule
lagom.serialization.json.jackson-modules += pt.min.saude.spms.sonhoos.poc.java.backend.api.CustomJacksonModule
akka {
# Enable supply serializer provided in Akka 2.5.8+ to avoid supply use of Java serialization.
actor.serialization-bindings {
"akka.Done" = akka-misc
"akka.actor.Address" = akka-misc
"akka.remote.UniqueAddress" = akka-misc
"java.util.UUID" = lagom-json
"io.vavr.control.Option" = lagom-json
"io.vavr.collection.List" = lagom-json
}
allow-java-serialization = off
}
We have run out of ideas. Its very difficult for us to adopt the java Apis coming from Scala background. Due to client policies we cant resort to using Scala.
As anyone ever successfully done this, what are we missing ?
p.s. only 2 links for new users ?!