Package io.github.astrapi69.json
Class ObjectToJsonExtensions
- java.lang.Object
-
- io.github.astrapi69.json.ObjectToJsonExtensions
-
public final class ObjectToJsonExtensions extends java.lang.Object
The classObjectToJsonExtensions
converts java objects to json string objects.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.lang.String
toJson(java.util.List<T> list)
Creates from the givenList
a json stringstatic <T> java.lang.String
toJson(java.util.List<T> list, com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates from the givenList
a json stringstatic <T> java.lang.String
toJson(T object)
Creates a jsonString
from the given argument objectstatic <T> java.lang.String
toJson(T object, boolean newMapper)
Creates a jsonString
from the given Objectstatic <T> java.lang.String
toJson(T object, com.fasterxml.jackson.databind.ObjectMapper mapper)
Creates a jsonString
from the given Object and the given object mapper
-
-
-
Method Detail
-
toJson
public static <T> java.lang.String toJson(java.util.List<T> list) throws com.fasterxml.jackson.core.JsonGenerationException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Creates from the givenList
a json string- Type Parameters:
T
- the generic type- Parameters:
list
- the list- Returns:
- the json string.
- Throws:
com.fasterxml.jackson.core.JsonGenerationException
- If an error occurs by writing json stringcom.fasterxml.jackson.databind.JsonMappingException
- the If an error occurs when mapping the string into Objectjava.io.IOException
- Signals that an I/O exception has occurred.
-
toJson
public static <T> java.lang.String toJson(java.util.List<T> list, com.fasterxml.jackson.databind.ObjectMapper mapper) throws java.io.IOException, com.fasterxml.jackson.core.JsonGenerationException, com.fasterxml.jackson.databind.JsonMappingException
Creates from the givenList
a json string- Type Parameters:
T
- the generic type- Parameters:
list
- the listmapper
- the object mapper- Returns:
- the string
- Throws:
java.io.IOException
- Signals that an I/O exception has occurredcom.fasterxml.jackson.core.JsonGenerationException
- the json generation exceptioncom.fasterxml.jackson.databind.JsonMappingException
- the json mapping exception
-
toJson
public static <T> java.lang.String toJson(T object) throws com.fasterxml.jackson.core.JsonProcessingException
Creates a jsonString
from the given argument object- Type Parameters:
T
- the generic type of the given argument object- Parameters:
object
- the object.- Returns:
- the json string.
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If an error occurs when converting object to String
-
toJson
public static <T> java.lang.String toJson(T object, boolean newMapper) throws com.fasterxml.jackson.core.JsonProcessingException
Creates a jsonString
from the given Object- Type Parameters:
T
- the generic type- Parameters:
object
- the objectnewMapper
- flag that indicates if a new ObjectMapper should be created. if true a new ObjectMapper will be created otherwise the ObjectMapper from this class will be returned.- Returns:
- the string
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If an error occurs when converting object to String
-
toJson
public static <T> java.lang.String toJson(T object, com.fasterxml.jackson.databind.ObjectMapper mapper) throws com.fasterxml.jackson.core.JsonProcessingException
Creates a jsonString
from the given Object and the given object mapper- Type Parameters:
T
- the generic type- Parameters:
object
- the objectmapper
- the object mapper- Returns:
- the string
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- the json processing exception
-
-