On Fri, Jul 10, 2020 at 8:29 PM 이동권 <
circ...@gmail.com> wrote:
>
>
> I don't know well, Post a question.
> I used Jackson Json Libraries with SpringBoot
>
> When i use @JsonSerialize(using = CustomSerializer.class) in severals POJO class Field
>
> CustomSerializer has no-args constructor with "initialized" logging command
> Jackson create Serializer instance for Each POJO class on Json Serialize Process.
>
> how can i create Serializer single instance, and share this.
>
> is it right thinking?
When using `JsonSerializer(using = )`, a new instance will be created
for every POJO type, correct.
If you would like to use one serializer instance for multiple types,
you should instead register serializers using `Module`.
For example, using `SimpleModule`:
-----
SimpleModule module = new SimpleModule();
module.addSerializer(Type1.class, serializerInstance);
module.addSerializer(Type2.class, serializerInstance);
ObjectMapper mapper = JsonMapper.builder().
.addModule(module)
.build();
-----
I hope this helps
-+Tatu +-