Class JsonApiConfiguration


  • public class JsonApiConfiguration
    extends java.lang.Object
    JSON:API specific configuration.
    • Constructor Detail

    • Method Detail

      • customize

        public JsonApiConfiguration customize​(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
        Customizes the object mapper if a customizer was set with withObjectMapperCustomizer.
        Parameters:
        objectMapper - the object mapper to be customized
        Returns:
        this JsonApiConfiguration
      • withTypeForClass

        public JsonApiConfiguration withTypeForClass​(java.lang.Class<?> clazz,
                                                     java.lang.String type)
        Creates a mapping for a given class to get the JSON:API resource object type when rendered.
        Parameters:
        clazz - must not be null.
        type - must not be null.
        Returns:
        a clone of this object, except with this updated property
      • getTypeForClass

        @Nullable
        public java.lang.String getTypeForClass​(java.lang.Class<?> clazz)
        Returns the JSON:API resource object type for a given class, when it was added with withTypeForClass(Class, String).
        Parameters:
        clazz - must not be null.
        Returns:
        can return null.
      • getClassForType

        @Nullable
        public java.lang.Class<?> getClassForType​(java.lang.String type)
        Returns the class for a given type, when the class was added with withTypeForClass(Class, String).
        Parameters:
        type - must not be null.
        Returns:
        can return null.
      • withPluralizedTypeRendered

        public JsonApiConfiguration withPluralizedTypeRendered​(boolean pluralizedTypeRendered)
        Indicates if the JSON:API type attribute of resource objects is pluralized.
        Parameters:
        pluralizedTypeRendered - The new value of this configuration's pluralizedTypeRendered
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isPluralizedTypeRendered

        public boolean isPluralizedTypeRendered()
        Indicates if the JSON:API type attribute of resource objects is pluralized.
        Returns:
        The default is true.
      • withLowerCasedTypeRendered

        public JsonApiConfiguration withLowerCasedTypeRendered​(boolean lowerCasedTypeRendered)
        Indicates if the JSON:API type attribute of resource objects is lower-cased.
        Parameters:
        lowerCasedTypeRendered - The new value of this configuration's lowerCasedTypeRendered
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isLowerCasedTypeRendered

        public boolean isLowerCasedTypeRendered()
        Indicates if the JSON:API type attribute of resource objects is lower-cased.
        Returns:
        The default is true.
      • withJsonApiVersionRendered

        public JsonApiConfiguration withJsonApiVersionRendered​(boolean jsonApiVersionRendered)
        Indicates if the JSON:API version is rendered.

        If set to true, each rendered JSON:API document will start with

         "jsonapi": {
            "version": "1.0"
         }
         
        Parameters:
        jsonApiVersionRendered - The new value of this configuration's jsonApiVersionRendered
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isJsonApiVersionRendered

        public boolean isJsonApiVersionRendered()
        Indicates if the JSON:API version is rendered.

        If set to true, each rendered JSON:API document will start with

         "jsonapi": {
            "version": "1.0"
         }
         
        Returns:
        The default is false.
      • withPageMetaAutomaticallyCreated

        public JsonApiConfiguration withPageMetaAutomaticallyCreated​(boolean pageMetaAutomaticallyCreated)
        Indicates if page metadata (rendered as top level JSON:API meta) for a paged model is created automatically.
        Parameters:
        pageMetaAutomaticallyCreated - The new value of this configuration's pageMetaAutomaticallyCreated
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isPageMetaAutomaticallyCreated

        public boolean isPageMetaAutomaticallyCreated()
        Indicates if page metadata (rendered as top level JSON:API meta) for a paged model is created automatically.
        Returns:
        The default is true.
      • withTypeForClassUsedForDeserialization

        public JsonApiConfiguration withTypeForClassUsedForDeserialization​(boolean typeForClassUsedForDeserialization)
        Indicates if the Java class to JSON:API mapping created with JsonApiConfiguration is also used during deserialization.
        Parameters:
        typeForClassUsedForDeserialization - The new value of this configuration's typeForClassUsedForDeserialization
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isTypeForClassUsedForDeserialization

        public boolean isTypeForClassUsedForDeserialization()
        Indicates if the Java class to JSON:API mapping created with JsonApiConfiguration is also used during deserialization.
        Returns:
        The default is false.
      • withAffordancesRenderedAsLinkMeta

        public JsonApiConfiguration withAffordancesRenderedAsLinkMeta​(JsonApiConfiguration.AffordanceType affordancesRenderedAsLinkMeta)
        Indicates if Spring HATEOAS affordances are rendered as JSON:API link meta. This feature is experimental, please don't use it in production yet. The format of the affordances will probably change. Currently, only a proprietary format (SPRING_HATEOAS) derived from the internal affordance model and HAL-FORMS _templates are supported.
        Parameters:
        affordancesRenderedAsLinkMeta - The new value of this configuration's affordancesRenderedAsLinkMeta
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • getAffordancesRenderedAsLinkMeta

        public JsonApiConfiguration.AffordanceType getAffordancesRenderedAsLinkMeta()
        Indicates if Spring HATEOAS affordances are rendered as JSON:API link meta. This feature is experimental, please don't use it in production yet. The format of the affordances will probably change. Currently, only a proprietary format (SPRING_HATEOAS) derived from the internal affordance model and HAL-FORMS _templates are supported.
        Returns:
        The list of JsonApiConfiguration.AffordanceType. The default is NONE, so no affordances will be rendered.
      • withEmptyAttributesObjectSerialized

        public JsonApiConfiguration withEmptyAttributesObjectSerialized​(boolean emptyAttributesObjectSerialized)
        Indicates if empty attributes are serialized as empty object.

        If set to true, empty attributes are serialized as

         {
           "data": {
              "id": "1",
              "type": "movies",
              "attributes": {
              }
           }
         }
         

        If set to false, attributes are not serialized,

         {
           "data": {
              "id": "1",
              "type": "movies"
           }
         }
         
        Parameters:
        emptyAttributesObjectSerialized - The new value of this configuration's emptyAttributesObjectSerialized
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • isEmptyAttributesObjectSerialized

        public boolean isEmptyAttributesObjectSerialized()
        Indicates if empty attributes are serialized as empty object.

        If set to true, empty attributes are serialized as

         {
           "data": {
              "id": "1",
              "type": "movies",
              "attributes": {
              }
           }
         }
         

        If set to false, attributes are not serialized,

         {
           "data": {
              "id": "1",
              "type": "movies"
           }
         }
         
        Returns:
        The default is true.
      • withJsonApiIdNotSerializedForValue

        public JsonApiConfiguration withJsonApiIdNotSerializedForValue​(java.lang.String jsonApiIdNotSerializedForValue)
        If you want to create JSON for a POST request that does not contain the id attribute. For example, if you set this property to "doNotSerialize" and initialize a Movie object with id = "doNotSerialize", the serialized JSON would look like
         {
           "data": {
              "type": "movies",
              "attributes": {
                 "title": "Star Wars"
               }
            }
         }
         
        Parameters:
        jsonApiIdNotSerializedForValue - The value of the JSON:API resource id that is ignored for serialization
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).
      • getJsonApiIdNotSerializedForValue

        public java.lang.String getJsonApiIdNotSerializedForValue()
        If you want to create JSON for a POST request that does not contain the id attribute. For example, if you set this property to "doNotSerialize" and initialize a Movie object with id = "doNotSerialize", the serialized JSON would look like
         {
           "data": {
              "type": "movies",
              "attributes": {
                 "title": "Star Wars"
               }
            }
         }
         
        Returns:
        The default is null.
      • withObjectMapperCustomizer

        public JsonApiConfiguration withObjectMapperCustomizer​(java.util.function.Consumer<com.fasterxml.jackson.databind.ObjectMapper> objectMapperCustomizer)
        You can pass a lambda expression to customize the ObjectMapper used for serialization.
        Parameters:
        objectMapperCustomizer - the ObjectMapper customizer
        Returns:
        a clone of this object, except with this updated property (returns this if an identical value is passed).