ch.ralscha.extdirectspring.util
Class JsonHandler

java.lang.Object
  extended by ch.ralscha.extdirectspring.util.JsonHandler

@Component
public class JsonHandler
extends Object


Constructor Summary
JsonHandler()
           
 
Method Summary
<T> T
convertValue(Object object, Class<T> clazz)
           
<T> T
readValue(String json, Class<T> clazz)
          Creates a object from a json String.
<T> T
readValue(String json, org.codehaus.jackson.type.TypeReference<T> typeReference)
          Creates a object from a json String.
 void setIndentMapper(org.codehaus.jackson.map.ObjectMapper indentMapper)
           
 void setMapper(org.codehaus.jackson.map.ObjectMapper mapper)
           
 String writeValueAsString(Object obj)
          Converts a object into a String containing the json representation of this object.
 String writeValueAsString(Object obj, boolean indent)
          Converts a object into a String containing the json representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonHandler

public JsonHandler()
Method Detail

setMapper

public void setMapper(org.codehaus.jackson.map.ObjectMapper mapper)

setIndentMapper

public void setIndentMapper(org.codehaus.jackson.map.ObjectMapper indentMapper)

writeValueAsString

public String writeValueAsString(Object obj)
Converts a object into a String containing the json representation of this object. In case of an exception returns null and logs the exception.

Parameters:
obj - the object to serialize into json
Returns:
obj in json format

writeValueAsString

public String writeValueAsString(Object obj,
                                 boolean indent)
Converts a object into a String containing the json representation of this object. In case of an exceptions returns null and logs the exception.

Parameters:
obj - the object to serialize into json
indent - if false writes json on one line
Returns:
obj in json format, null if there is an exception

readValue

public <T> T readValue(String json,
                       org.codehaus.jackson.type.TypeReference<T> typeReference)
Creates a object from a json String. In case of an exception returns null and logs the exception.

Type Parameters:
T - type of the object to create
Parameters:
json - String with the json
typeReference - TypeReference instance of the desired result type TypeReference
Returns:
the created object, null if there is an exception

readValue

public <T> T readValue(String json,
                       Class<T> clazz)
Creates a object from a json String. In case of an exception returns null and logs the exception.

Type Parameters:
T - type of the object to create
Parameters:
json - String with the json
clazz - Class of object to create
Returns:
the created object, null if there is an exception

convertValue

public <T> T convertValue(Object object,
                          Class<T> clazz)


Copyright © 2010-2011. All Rights Reserved.