Package org.gitlab4j.models.utils
Class JacksonJson
- java.lang.Object
-
- org.gitlab4j.models.utils.JacksonJson
-
public class JacksonJson extends java.lang.Object
Jackson JSON Configuration and utility class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JacksonJson.DateOnlySerializer
JsonSerializer for serializing dates s yyyy-mm-dd in UTC timezone.static class
JacksonJson.JsonDateDeserializer
JsonDeserializer for deserializing ISO8601 formatted dates.static class
JacksonJson.JsonDateSerializer
JsonSerializer for serializing ISO8601 formatted dates.static class
JacksonJson.UserListDeserializer
Deserializer for the odd User instances in the "approved_by" array in the merge_request JSON.static class
JacksonJson.UserListSerializer
Serializer for the odd User instances in the "approved_by" array in the merge_request JSON.
-
Constructor Summary
Constructors Constructor Description JacksonJson()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Gets the ObjectMapper contained by this instance.<T> java.lang.String
marshal(T object)
Marshals the supplied object out as a formatted JSON string.com.fasterxml.jackson.databind.JsonNode
readTree(java.io.Reader reader)
Reads and parses the JSON data on the specified Reader instance to a JsonNode tree representation.com.fasterxml.jackson.databind.JsonNode
readTree(java.lang.String postData)
Reads and parses the String containing JSON data and returns a JsonNode tree representation.static com.fasterxml.jackson.databind.JsonNode
toJsonNode(java.lang.String jsonString)
Parse the provided String into a JsonNode instance.static <T> java.lang.String
toJsonString(T object)
Gets a the supplied object output as a formatted JSON string.<T> T
unmarshal(java.lang.Class<T> returnType, com.fasterxml.jackson.databind.JsonNode tree)
Unmarshal the JsonNode (tree) to an instance of the provided class.<T> T
unmarshal(java.lang.Class<T> returnType, java.io.Reader reader)
Unmarshal the JSON data on the specified Reader instance to an instance of the provided class.<T> T
unmarshal(java.lang.Class<T> returnType, java.lang.String postData)
Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class.<T> java.util.List<T>
unmarshalList(java.lang.Class<T> returnType, java.io.Reader reader)
Unmarshal the JSON data on the specified Reader instance and populate a List of instances of the provided returnType class.<T> java.util.List<T>
unmarshalList(java.lang.Class<T> returnType, java.lang.String postData)
Unmarshal the JSON data contained by the string and populate a List of instances of the provided returnType class.<T> java.util.Map<java.lang.String,T>
unmarshalMap(java.lang.Class<T> returnType, java.io.Reader reader)
Unmarshal the JSON data on the specified Reader instance and populate a Map of String keys and values of the provided returnType class.<T> java.util.Map<java.lang.String,T>
unmarshalMap(java.lang.Class<T> returnType, java.lang.String jsonData)
Unmarshal the JSON data and populate a Map of String keys and values of the provided returnType class.
-
-
-
Method Detail
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Gets the ObjectMapper contained by this instance.- Returns:
- the ObjectMapper contained by this instance
-
readTree
public com.fasterxml.jackson.databind.JsonNode readTree(java.lang.String postData) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Reads and parses the String containing JSON data and returns a JsonNode tree representation.- Parameters:
postData
- a String holding the POST data- Returns:
- a JsonNode instance containing the parsed JSON
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
readTree
public com.fasterxml.jackson.databind.JsonNode readTree(java.io.Reader reader) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Reads and parses the JSON data on the specified Reader instance to a JsonNode tree representation.- Parameters:
reader
- the Reader instance that contains the JSON data- Returns:
- a JsonNode instance containing the parsed JSON
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshal
public <T> T unmarshal(java.lang.Class<T> returnType, com.fasterxml.jackson.databind.JsonNode tree) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JsonNode (tree) to an instance of the provided class.- Type Parameters:
T
- the generics type for the return value- Parameters:
returnType
- an instance of this type class will be returnedtree
- the JsonNode instance that contains the JSON data- Returns:
- an instance of the provided class containing the data from the tree
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshal
public <T> T unmarshal(java.lang.Class<T> returnType, java.io.Reader reader) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data on the specified Reader instance to an instance of the provided class.- Type Parameters:
T
- the generics type for the return value- Parameters:
returnType
- an instance of this type class will be returnedreader
- the Reader instance that contains the JSON data- Returns:
- an instance of the provided class containing the parsed data from the Reader
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshal
public <T> T unmarshal(java.lang.Class<T> returnType, java.lang.String postData) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data contained by the string and populate an instance of the provided returnType class.- Type Parameters:
T
- the generics type for the return value- Parameters:
returnType
- an instance of this type class will be returnedpostData
- a String holding the POST data- Returns:
- an instance of the provided class containing the parsed data from the string
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshalList
public <T> java.util.List<T> unmarshalList(java.lang.Class<T> returnType, java.io.Reader reader) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data on the specified Reader instance and populate a List of instances of the provided returnType class.- Type Parameters:
T
- the generics type for the List- Parameters:
returnType
- an instance of this type class will be contained in the returned Listreader
- the Reader instance that contains the JSON data- Returns:
- a List of the provided class containing the parsed data from the Reader
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshalList
public <T> java.util.List<T> unmarshalList(java.lang.Class<T> returnType, java.lang.String postData) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data contained by the string and populate a List of instances of the provided returnType class.- Type Parameters:
T
- the generics type for the List- Parameters:
returnType
- an instance of this type class will be contained in the returned ListpostData
- a String holding the POST data- Returns:
- a List of the provided class containing the parsed data from the string
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshalMap
public <T> java.util.Map<java.lang.String,T> unmarshalMap(java.lang.Class<T> returnType, java.io.Reader reader) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data on the specified Reader instance and populate a Map of String keys and values of the provided returnType class.- Type Parameters:
T
- the generics type for the Map value- Parameters:
returnType
- an instance of this type class will be contained the values of the Mapreader
- the Reader instance that contains the JSON data- Returns:
- a Map containing the parsed data from the Reader
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
unmarshalMap
public <T> java.util.Map<java.lang.String,T> unmarshalMap(java.lang.Class<T> returnType, java.lang.String jsonData) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, java.io.IOException
Unmarshal the JSON data and populate a Map of String keys and values of the provided returnType class.- Type Parameters:
T
- the generics type for the Map value- Parameters:
returnType
- an instance of this type class will be contained the values of the MapjsonData
- the String containing the JSON data- Returns:
- a Map containing the parsed data from the String
- Throws:
com.fasterxml.jackson.core.JsonParseException
- when an error occurs parsing the provided JSONcom.fasterxml.jackson.databind.JsonMappingException
- if a JSON error occursjava.io.IOException
- if an error occurs reading the JSON data
-
marshal
public <T> java.lang.String marshal(T object)
Marshals the supplied object out as a formatted JSON string.- Type Parameters:
T
- the generics type for the provided object- Parameters:
object
- the object to output as a JSON string- Returns:
- a String containing the JSON for the specified object
-
toJsonString
public static <T> java.lang.String toJsonString(T object)
Gets a the supplied object output as a formatted JSON string. Null properties will result in the value of the property being null. This is meant to be used for toString() implementations of GitLab4J classes.- Type Parameters:
T
- the generics type for the provided object- Parameters:
object
- the object to output as a JSON string- Returns:
- a String containing the JSON for the specified object
-
toJsonNode
public static com.fasterxml.jackson.databind.JsonNode toJsonNode(java.lang.String jsonString) throws java.io.IOException
Parse the provided String into a JsonNode instance.- Parameters:
jsonString
- a String containing JSON to parse- Returns:
- a JsonNode with the String parsed into a JSON tree
- Throws:
java.io.IOException
- if any IO error occurs
-
-