I'm writing a Spring boot application that uses RestController to expose one resource. The only resource, MainResource, is something like this:
String id;
String title;
List<String> tags;
ComplexGraphObject gObject;
To make this work I wrote DTOs for the MainResource and for gObject and its fields where necessary. I annotated the DTOs with Jackson and wrote DTO-Mappers that return domain models. Spring correctly serializes the requests to the DTOs and an application service calls the DTO-Mappers for domain objects.
I've now realized that the gObject should be its own library, as we'd like to use it for client and server applications.
My objectives are:
- The library should take serialized gObjects in json/xml and return domain objects.
- The library should take domain gObjects and return serialized json/xml
- Enable applications that already use Jackson to work seamlessly as possible with the library like Spring Boot for example
- Provide convenience methods for other applications that might use something like gson for example
From what I've read a custom jackson de/serializer is the way to go. But between custom serializers, ObjectMapper, MixIns, etc I don't know how to do it.
EDIT: I think the mixins purpose is kinda what my DTOs are doing, and the DTO-Mapper is kinda doing what the custom de/serializer should. Is there a way to mix the two?
EDIT: Important part I forgot. The DTO-Mapper generates domain objects from the DTO as well as a matrix that represents the needed relationships from each node in the graph so they can be connected accordingly. So I guess I'd need to do that in the custom serializer?