Class JsonApiConfiguration
- java.lang.Object
-
- com.toedter.spring.hateoas.jsonapi.JsonApiConfiguration
-
public class JsonApiConfiguration extends java.lang.Object
JSON:API specific configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JsonApiConfiguration.AffordanceType
-
Constructor Summary
Constructors Constructor Description JsonApiConfiguration()
Creates a new defaultJsonApiConfiguration
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonApiConfiguration
customize(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Customizes the object mapper if a customizer was set with withObjectMapperCustomizer.JsonApiConfiguration.AffordanceType
getAffordancesRenderedAsLinkMeta()
Indicates if Spring HATEOAS affordances are rendered as JSON:API link meta.java.lang.Class<?>
getClassForType(java.lang.String type)
Returns the class for a given type, when the class was added withwithTypeForClass(Class, String)
.java.lang.String
getTypeForClass(java.lang.Class<?> clazz)
Returns the JSON:API resource object type for a given class, when it was added withwithTypeForClass(Class, String)
.boolean
isEmptyAttributesObjectSerialized()
Indicates if empty attributes are serialized as empty object.boolean
isJsonApiVersionRendered()
Indicates if the JSON:API version is rendered.boolean
isLowerCasedTypeRendered()
Indicates if the JSON:API type attribute of resource objects is lower-cased.boolean
isPageMetaAutomaticallyCreated()
Indicates if page metadata (rendered as top level JSON:API meta) for a paged model is created automatically.boolean
isPluralizedTypeRendered()
Indicates if the JSON:API type attribute of resource objects is pluralized.boolean
isTypeForClassUsedForDeserialization()
Indicates if the Java class to JSON:API mapping created withJsonApiConfiguration
is also used during deserialization.JsonApiConfiguration
withAffordancesRenderedAsLinkMeta(JsonApiConfiguration.AffordanceType affordancesRenderedAsLinkMeta)
Indicates if Spring HATEOAS affordances are rendered as JSON:API link meta.JsonApiConfiguration
withEmptyAttributesObjectSerialized(boolean emptyAttributesObjectSerialized)
Indicates if empty attributes are serialized as empty object.JsonApiConfiguration
withJsonApiVersionRendered(boolean jsonApiVersionRendered)
Indicates if the JSON:API version is rendered.JsonApiConfiguration
withLowerCasedTypeRendered(boolean lowerCasedTypeRendered)
Indicates if the JSON:API type attribute of resource objects is lower-cased.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.JsonApiConfiguration
withPageMetaAutomaticallyCreated(boolean pageMetaAutomaticallyCreated)
Indicates if page metadata (rendered as top level JSON:API meta) for a paged model is created automatically.JsonApiConfiguration
withPluralizedTypeRendered(boolean pluralizedTypeRendered)
Indicates if the JSON:API type attribute of resource objects is pluralized.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.JsonApiConfiguration
withTypeForClassUsedForDeserialization(boolean typeForClassUsedForDeserialization)
Indicates if the Java class to JSON:API mapping created withJsonApiConfiguration
is also used during deserialization.
-
-
-
Constructor Detail
-
JsonApiConfiguration
public JsonApiConfiguration()
Creates a new defaultJsonApiConfiguration
.
-
-
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 withwithTypeForClass(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 withwithTypeForClass(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 withJsonApiConfiguration
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 withJsonApiConfiguration
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 {#link AffordanceType}. The default is NONE, so no affordances will be rendered.
-
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).
-
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, like { "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, like { "data": { "id": "1", "type": "movies" } }
- Returns:
- The default is true.
-
-