Closed ASchmidt84 closed 2 years ago
In theory, yes. The play-json serializer in Permission won't help with akka jackson serialization.
Have a look at https://doc.akka.io/docs/akka/current/serialization-jackson.html#jackson-modules and see if adding "com.github.pjfanning.enumeratum.EnumeratumModule" helps. You will need to add the library as a dependency too in your sbt script.
If this approach doesn't work, you might need to try writing a custom jackson serializer for Permission class. See the part in https://doc.akka.io/docs/akka/current/serialization-jackson.html that describes that does this.
@JsonSerialize(`using` = classOf[DirectionJsonSerializer])
@JsonDeserialize(`using` = classOf[DirectionJsonDeserializer])
Hi,
okay I added it. But after build and run I get the error
Could not load configured Jackson module [com.github.pjfanning.enumeratum.EnumeratumModule], please verify classpath dependencies or amend the configuration [akka.serialization.jackson-modules]. Continuing without this module.
java.lang.ClassCastException: class com.fasterxml.jackson.databind.Module is not assignable from class com.github.pjfanning.enumeratum.EnumeratumModule
I added it to sbt don´t know why it does not find.
EnumeratumModule does extend com.fasterxml.jackson.databind.Module - I have unit tests to prove it
You will need to talk to the Lagom team. I suspect that you might have jar version mismatches on your classpath.
yes i think it too.
You also have the option of writing a custom serializer as I suggested above.
I will look at write a custom serializer. To get an answer from lightbend is like asking god. 🤣 For better understanding. I change my lib to:
"com.beachape" %% "enumeratum-play-json" % "1.7.0",
"com.github.pjfanning" %% "jackson-module-enumeratum" % "2.13.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.13.0"
and added to my conf:
akka.actor {
serialization-bindings {
# Commands won't use play-json but Akka's jackson support.
# See https://doc.akka.io/docs/akka/2.6/serialization-jackson.html
# "com.example.shoppingcart.impl.ShoppingCart$CommandSerializable" = jackson-json
"io.coup.avalon.security.impl.user.UserProfile$CommandSerializable" = jackson-json
}
}
akka.serialization.jackson{
jackson-modules += "com.fasterxml.jackson.datatype.pcollections.PCollectionsModule"
jackson-modules += "com.fasterxml.jackson.datatype.guava.GuavaModule"
jackson-modules += "com.github.pjfanning.enumeratum.EnumeratumModule"
}
Do i need to init the module somewhere additional? Thank yoou for your help
I have never used Lagom and I have never used akka jackson integration.
One thing to watch out for is that akka tends not to use the latest jackson versions - you might want to try to match the version of your jackson dependencies to the version of jackson that your akka version uses - eg if akka needs 2.12.x, then use a 2.12.x version of jackson-module-scala and jackson-module-enumeratum - if you need jackson 2.11 support, then just use jackson-module-enumeratum 2.12.x and exclude its transitive dependencies so that you don't cause jackson databind to be upgraded - see the exclude support in https://www.scala-sbt.org/1.x/docs/Library-Management.html
it might be worth trying
jackson-modules += "com.github.pjfanning.enumeratum.EnumeratumModule$"
if akka jackson support is using Java reflection, then com.github.pjfanning.enumeratum.EnumeratumModule$ is the name of the class that backs the EnumeratumModule scala object
@ASchmidt84 I did a change that might help - https://github.com/pjfanning/jackson-module-enumeratum/issues/4 (there is a published snapshot with this change)
@pjfanning the missing $ seems to be the problem 👍 I will have a deeper look
Yes this solves it 👍 Great idea! Thank you.
Hi, i am using enumeratum and created a permission enum
In dev mode all is working fine. In prod mode I get an jackson error.
in application.conf
Now my question with adding jackson-module-enumeratum will this work?
Thank you.