JODD json configuration in spring project

68 Views Asked by At

My question is simple .

MappingJackson2HttpMessageConverter

is available in spring for data serialization from any rest service to client. Now I am working on another project and it has recommendation to use JODD json. I am confused how to configure same in spring project as a

custom and generic to all Json convertor

for all RestApi Responses.

Thanks , in Advance

1

There are 1 best solutions below

0
igr On

If I understood correctly, you want to know how to do the mapping between types and JSON. Jodd is doing this as best it can with what's given to it. For serialization, just give the object, Jodd will parse. For parsing, just provide the target class, and Jodd will try to do the best to create all the possible classes, with regards of current types, generics, etc.

Sometimes you need more:

annotations

With annotations you can fine tune e.g. naming and what is going to be serialized. Just add @JSON annotation to classes/methods/fields and tweak.

serializers and parsers

But you can specify specific serializer or parser for each type you wanna process. Use:

TypeJsonSerializerMap.get().register()

to add a new TypeJsonSerializer, or

TypeJsonParserMap.get().register();

to add a new TypeJsonParser.

Note: TypeJsonParserMap is not yet released, but will be soon.