@Service(value="JacksonMapper")
public class JacksonMapper
extends java.lang.Object
Jackson Documentation permits to use mapper with a single instance, it is ThreadSafe: from Jackson Doc... "ObjectReader/ObjectWriter: these are light-weight immutable objects that can be safely shared between threads (and thus reused) as well"
Example of use: jacksonMapper.toJson(myDTO) = return String of Json
Modifier and Type | Field and Description |
---|---|
private com.fasterxml.jackson.databind.ObjectMapper |
mapper |
private com.fasterxml.jackson.databind.ObjectWriter |
writer |
Constructor and Description |
---|
JacksonMapper() |
Modifier and Type | Method and Description |
---|---|
<T> T |
fromJson(java.lang.String json,
java.lang.Class<T> myClass)
Easier function to convert a string json to object
|
<T> com.fasterxml.jackson.databind.ObjectReader |
getReader(java.lang.Class<T> myClass)
this method return a ready to operate reader, it is customized for class.
|
private void |
initialize()
this method is the Spring implementation of Singleton.
|
java.lang.String |
toJson(java.lang.Object object)
this method is a simple wrapper of writeValueAsString of writer.
|
private com.fasterxml.jackson.databind.ObjectMapper mapper
private com.fasterxml.jackson.databind.ObjectWriter writer
@Autowired private void initialize()
public java.lang.String toJson(java.lang.Object object) throws com.fasterxml.jackson.core.JsonProcessingException
Example of use: jacksonMapper.toJson(myDTO) = return String of Json
object
- that you want to convertcom.fasterxml.jackson.core.JsonProcessingException
public <T> com.fasterxml.jackson.databind.ObjectReader getReader(java.lang.Class<T> myClass)
myClass
- public <T> T fromJson(java.lang.String json, java.lang.Class<T> myClass) throws java.io.IOException
json
- String of jsonmyClass
- this is the class of destination of the mappingjava.io.IOException
- if the conversion failed