Package com.github.jasminb.jsonapi
Class JSONAPIDocument<T>
- java.lang.Object
-
- com.github.jasminb.jsonapi.JSONAPIDocument<T>
-
- Type Parameters:
T- the type parameter
public class JSONAPIDocument<T> extends Object
JSON API Document wrapper.- Author:
- jbegic
-
-
Constructor Summary
Constructors Constructor Description JSONAPIDocument()Creates new JSONAPIDocument.JSONAPIDocument(Error error)Creates new JSONAPIDocument.JSONAPIDocument(Iterable<? extends Error> errors)Creates new JSONAPIDocument.JSONAPIDocument(T data)Creates new JsonApiDocument.JSONAPIDocument(T data, com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.databind.ObjectMapper deserializer)Creates new JSONAPIDocument.JSONAPIDocument(T data, com.fasterxml.jackson.databind.ObjectMapper deserializer)Creates new JSONAPIDocument.JSONAPIDocument(T data, Links links, Map<String,Object> meta)Creates new JsonApiDocument.JSONAPIDocument(T data, Links links, Map<String,Object> meta, com.fasterxml.jackson.databind.ObjectMapper deserializer)Creates new JsonApiDocument.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLink(String linkName, Link link)Adds a named link.voidaddMeta(String key, Object value)static @NotNull JSONAPIDocument<?>createErrorDocument(Iterable<? extends Error> errors)Factory method for creating JSONAPIDocument that holds the Error object.Tget()Gets resource object@Nullable Iterable<? extends Error>getErrors()Returns error objects ornullin case no errors were set.JsonApigetJsonApi()Returns JSON API object if present.@Nullable LinksgetLinks()Gets links.@Nullable Map<String,?>getMeta()Get meta data.<M> MgetMeta(Class<?> metaType)Returns typed meta-data object ornullif no meta is present.com.fasterxml.jackson.databind.JsonNodegetResponseJSONNode()Returns raw JSON node used to createthisJSONAPIDocument.voidsetJsonApi(JsonApi jsonApi)Sets the JSON API object.voidsetLinks(Links links)Sets links.voidsetMeta(Map<String,?> meta)Sets meta data.
-
-
-
Constructor Detail
-
JSONAPIDocument
public JSONAPIDocument(T data)
Creates new JsonApiDocument.- Parameters:
data-JSONAPIDocumentAPI resource type
-
JSONAPIDocument
public JSONAPIDocument(T data, com.fasterxml.jackson.databind.ObjectMapper deserializer)
Creates new JSONAPIDocument.- Parameters:
data-JSONAPIDocumentAPI resource typedeserializer-ObjectMapperdeserializer to be used for handling meta conversion
-
JSONAPIDocument
public JSONAPIDocument(T data, com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.databind.ObjectMapper deserializer)
Creates new JSONAPIDocument.- Parameters:
data-JSONAPIDocumentAPI resource typejsonNode-JsonNoderesponse JSONdeserializer-ObjectMapperdeserializer to be used for handling meta conversion
-
JSONAPIDocument
public JSONAPIDocument(T data, Links links, Map<String,Object> meta)
Creates new JsonApiDocument.- Parameters:
data-JSONAPIDocumentAPI resource typelinks-
-
JSONAPIDocument
public JSONAPIDocument(T data, Links links, Map<String,Object> meta, com.fasterxml.jackson.databind.ObjectMapper deserializer)
Creates new JsonApiDocument.- Parameters:
data-JSONAPIDocumentAPI resource typelinks-
-
JSONAPIDocument
public JSONAPIDocument()
Creates new JSONAPIDocument.
-
JSONAPIDocument
public JSONAPIDocument(Iterable<? extends Error> errors)
Creates new JSONAPIDocument.- Parameters:
errors- errors
-
JSONAPIDocument
public JSONAPIDocument(Error error)
Creates new JSONAPIDocument.- Parameters:
error- error
-
-
Method Detail
-
createErrorDocument
@NotNull public static @NotNull JSONAPIDocument<?> createErrorDocument(Iterable<? extends Error> errors)
Factory method for creating JSONAPIDocument that holds the Error object.This method should be used in case error response is being built by the server side.
- Parameters:
errors-
-
get
@Nullable public T get()
Gets resource object- Returns:
JSONAPIDocumentresource object
-
getLinks
@Nullable public @Nullable Links getLinks()
Gets links.- Returns:
- the links
-
addLink
public void addLink(String linkName, Link link)
Adds a named link.- Parameters:
linkName- the named link to addlink- the link to add
-
setLinks
public void setLinks(Links links)
Sets links.- Parameters:
links- the links
-
getMeta
@Nullable public <M> M getMeta(Class<?> metaType)
Returns typed meta-data object ornullif no meta is present.- Type Parameters:
M- type- Parameters:
metaType-Classtarget type- Returns:
- meta or
null
-
getErrors
@Nullable public @Nullable Iterable<? extends Error> getErrors()
Returns error objects ornullin case no errors were set.- Returns:
Iterableerrors
-
getResponseJSONNode
public com.fasterxml.jackson.databind.JsonNode getResponseJSONNode()
Returns raw JSON node used to createthisJSONAPIDocument.- Returns:
JsonNode
-
-