티스토리 뷰

Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read or write calls. If configuration of a mapper instance is modified after first usage, changes may or may not take effect, and configuration calls themselves may fail. If you need to use different configuration, you have two main possibilities

매퍼 인스턴스는 인스턴스의 모든 구성이 읽기 또는 쓰기 호출 전에 수행되는 경우 완전히 스레드 안전합니다. 처음 사용한 후에 매퍼 인스턴스의 구성을 수정하면 변경 사항이 적용되거나 적용되지 않을 수 있으며, 구성 호출 자체가 실패할 수도 있습니다. 다른 구성을 사용해야 하는 경우 크게 두 가지 가능성이 있습니다

Note that copy operation is as expensive as constructing a new ObjectMapper instance: if possible, you should still pool and reuse mappers if you intend to use them for multiple operations.

복사 작업은 새 ObjectMapper 인스턴스를 생성하는 것만큼 비용이 많이 들기 때문에 여러 작업에 매퍼를 사용하려는 경우 가능하면 매퍼를 풀링하여 재사용하는 것이 좋습니다.

Simplest usage is of form:
final ObjectMapper mapper = new ObjectMapper(); // can use static singleton, inject: just make sure to reuse!

즉, ObjectMapper 자체 구성 메소드(setDateFormat, setConfig)를 호출하지 않았을때 스레드 안전하며, singleton으로 재사용이 가능하다.

 

springboot 에서도 jackson ObjectMapper를 Bean으로 등록해서 사용하고있다.