play-json icon indicating copy to clipboard operation
play-json copied to clipboard

JacksonJson cannot be used with akka serialization as a jackson module

Open jona7o opened this issue 2 years ago • 0 comments

Hi,

i would be great if you could add another class without class parameters to https://github.com/playframework/play-json/blob/main/play-json/jvm/src/main/scala/play/api/libs/json/jackson/JacksonJson.scala

Something like:

class JacksonJsonModule() extends SimpleModule("JacksonJsonModule", Version.unknownVersion()) {
  val parserSettings = JsonParserSettings()
  override def setupModule(context: SetupContext): Unit = {
    context.addDeserializers(new PlayDeserializers(parserSettings))
    context.addSerializers(new PlaySerializers(parserSettings))
  }
}

Why i think it is useful? Because i want to register the JacksonJson in the akka config, and akka can just create an instance of the class if it has no parameters.

akka.serialization.jackson {
    jackson-modules += "[..].JacksonJsonModule" # <--- Right now this is not possible
}

It is useful if you use JsValue in a case class which gets serialized by akka. When it comes to deserialization you now enter in an

InvalidDefinitionException: Cannot construct instance of ... (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

Perhaps you have another solution, but my current solution was to fork the file and add a class like mentioned for my purpose.

jona7o avatar Jun 20 '22 22:06 jona7o