Class JSONAPIDocument<T>

  • Type Parameters:
    T - the type parameter

    public class JSONAPIDocument<T>
    extends Object
    JSON API Document wrapper.
    Author:
    jbegic
    • Constructor Detail

      • JSONAPIDocument

        public JSONAPIDocument​(T data)
        Creates new JsonApiDocument.
        Parameters:
        data - JSONAPIDocument API resource type
      • JSONAPIDocument

        public JSONAPIDocument​(T data,
                               com.fasterxml.jackson.databind.ObjectMapper deserializer)
        Creates new JSONAPIDocument.
        Parameters:
        data - JSONAPIDocument API resource type
        deserializer - ObjectMapper deserializer 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 - JSONAPIDocument API resource type
        jsonNode - JsonNode response JSON
        deserializer - ObjectMapper deserializer to be used for handling meta conversion
      • JSONAPIDocument

        public JSONAPIDocument​(T data,
                               Links links,
                               Map<String,​Object> meta)
        Creates new JsonApiDocument.
        Parameters:
        data - JSONAPIDocument API resource type
        links -
      • JSONAPIDocument

        public JSONAPIDocument​(T data,
                               Links links,
                               Map<String,​Object> meta,
                               com.fasterxml.jackson.databind.ObjectMapper deserializer)
        Creates new JsonApiDocument.
        Parameters:
        data - JSONAPIDocument API resource type
        links -
      • 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:
        JSONAPIDocument resource object
      • getMeta

        @Nullable
        public @Nullable Map<String,​?> getMeta()
        Get meta data.
        Returns:
        Map meta
      • setMeta

        public void setMeta​(Map<String,​?> meta)
        Sets meta data.
        Parameters:
        meta - Map meta
      • addMeta

        public void addMeta​(String key,
                            Object value)
      • 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 add
        link - 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 or null if no meta is present.
        Type Parameters:
        M - type
        Parameters:
        metaType - Class target type
        Returns:
        meta or null
      • getErrors

        @Nullable
        public @Nullable Iterable<? extends Error> getErrors()
        Returns error objects or null in case no errors were set.
        Returns:
        Iterable errors
      • getResponseJSONNode

        public com.fasterxml.jackson.databind.JsonNode getResponseJSONNode()
        Returns raw JSON node used to create this JSONAPIDocument.
        Returns:
        JsonNode
      • getJsonApi

        public JsonApi getJsonApi()
        Returns JSON API object if present.
        Returns:
        JsonApi or null
      • setJsonApi

        public void setJsonApi​(JsonApi jsonApi)
        Sets the JSON API object.
        Parameters:
        jsonApi - JsonApi