JsonUtils.Impl| Constructor and Description |
|---|
JsonUtils.Impl(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Required-Args constructor
|
| Modifier and Type | Method and Description |
|---|---|
<P> P |
fromJson(javax.servlet.http.HttpServletRequest httpServletRequest,
JsonUtilsClassTypeMapper jsonUtilsClassTypeMapper)
Convert the body of an
HttpServletRequest into an of the proper
type as based upon an instance of JsonUtilsClassTypeMapper. |
<P> P |
fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<P> jsonNodeClass)
Convert a
JsonNode into an object of the proper type as found in
the "@class" directive in the JsonNode. |
<P> P |
fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode,
JsonUtilsClassTypeMapper jsonUtilsClassTypeMapper)
Convert the body of an
HttpServletRequest into an of the proper
type as based upon an instance of JsonUtilsClassTypeMapper. |
protected com.fasterxml.jackson.databind.JsonNode |
getRequestPayloadAsJsonNode(javax.servlet.http.HttpServletRequest request)
Retrieves the
JsonNode from the request. |
protected String |
getRequestPayloadAsJsonString(javax.servlet.http.HttpServletRequest httpServletRequest)
Helper method to grab a Json Payload from an
HttpServletRequest by forwarding to
getRequestPayloadAsJsonString(InputStream). |
protected String |
getRequestPayloadAsJsonString(InputStream inputStream)
Helper method to grab a Json Payload from an
InputStream. |
<T> String |
toJson(T payload)
Convert an object of type
|
<P> String |
toJsonUnchecked(P payload)
Convert an object of type
|
protected static final Logger logger
public JsonUtils.Impl(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper - public <T> String toJson(T payload) throws com.fasterxml.jackson.core.JsonProcessingException
JsonUtilsinto a Json String.
public <P> String toJsonUnchecked(P payload) throws RuntimeException
JsonUtils
into a Json String. Catch any exceptions of type
JsonProcessingException and throw them as
RuntimeException.
toJsonUnchecked in interface JsonUtilsRuntimeExceptionpublic <P> P fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode,
JsonUtilsClassTypeMapper jsonUtilsClassTypeMapper)
throws ClassNotFoundException
JsonUtilsHttpServletRequest into an of the proper
type as based upon an instance of JsonUtilsClassTypeMapper.fromJson in interface JsonUtilsjsonNode - A JsonNode to deserialize into a Java object.jsonUtilsClassTypeMapper - An instance of
JsonUtilsClassTypeMapper to map the incoming JSON
payload to a typed Java class.ClassNotFoundExceptionpublic <P> P fromJson(com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<P> jsonNodeClass)
throws ClassNotFoundException
JsonUtilsJsonNode into an object of the proper type as found in
the "@class" directive in the JsonNode.fromJson in interface JsonUtilsjsonNode - A JsonNode to deserialize into a Java object.jsonNodeClass - The expected Java Class to deserialize the
incoming JSON payload to.ClassNotFoundExceptionpublic <P> P fromJson(javax.servlet.http.HttpServletRequest httpServletRequest,
JsonUtilsClassTypeMapper jsonUtilsClassTypeMapper)
throws IOException,
ClassNotFoundException
JsonUtilsHttpServletRequest into an of the proper
type as based upon an instance of JsonUtilsClassTypeMapper.fromJson in interface JsonUtilshttpServletRequest - An HttpServletRequest with an
InputStream containing a JSON payload.jsonUtilsClassTypeMapper - An instance of
JsonUtilsClassTypeMapper to map the incoming JSON
payload to a typed Java class.IOExceptionClassNotFoundExceptionprotected com.fasterxml.jackson.databind.JsonNode getRequestPayloadAsJsonNode(javax.servlet.http.HttpServletRequest request)
throws IOException,
ClassNotFoundException
JsonNode from the request.request - IOExceptionClassNotFoundExceptionprotected String getRequestPayloadAsJsonString(javax.servlet.http.HttpServletRequest httpServletRequest) throws IOException
HttpServletRequest by forwarding to
getRequestPayloadAsJsonString(InputStream).httpServletRequest - An instance of HttpServletRequest.IOExceptionprotected String getRequestPayloadAsJsonString(InputStream inputStream) throws IOException
InputStream.
This is generally used in concert with an HttpServletRequest,
but doesn't strictly need to be. Not used in this class but used by
sub-classes.inputStream - An instance of InputStream.IOExceptionCopyright © 2014–2015 Sappenin Inc.. All rights reserved.