I'm getting started using Lagom in Java and have a need to write a custom (de)serializer. I've read through the documents and understand the roles of the NegotiatedSerializer, MessageSerializer, SerializerFactory etc. What I don't understand is in which package it is canonical to define the class. I've looked at the Chirper sample and see that there are often concrete model definitions alongside the *Service interfaces in the various *API modules, but there are no examples of custom Serializers. Thanks for the help!
1 Answers
Serializers for messages (request bodies, response bodies, and messages published to a topic) should be part of the service's api
module. Serializers need to be used both by clients of the service and by the service implementation itself. This makes them part of the service interface or API.
Serializers for persistence (commands and replies, persistence events, entity state) should be defined in each service's impl
module. They are details of the internal implementation and should not be exposed to clients.
Beyond those broad guidelines, the way you organize your package structure is really up to you. Some projects use a single package for the API and a different one for the implementation. Others might divide each into sub-packages, though as services should generally stay pretty small and focused, this might be overkill. You should arrange the packages in a way that makes sense for your project and organization.

- 8,958
- 2
- 23
- 34
-
Thanks much, that makes sense! – Josh Wickham Feb 14 '17 at 02:20