Class EnumTranslator
java.lang.Object
org.springframework.data.rest.webmvc.json.EnumTranslator
- All Implemented Interfaces:
EnumTranslationConfiguration
Configuration to tweak enum serialization.
- Author:
- Oliver Gierke
-
Constructor Summary
ConstructorsConstructorDescriptionEnumTranslator(org.springframework.hateoas.mediatype.MessageResolver resolver) Creates a newEnumTranslatorusing the givenMessageSourceAccessor. -
Method Summary
Modifier and TypeMethodDescriptionResolves the given enum value into aStringconsulting the configuredMessageSourceAccessorpotentially falling back to the default translation if configured.<T extends Enum<?>>
TParses the given source text into the corresponding enum value using the configuredMessageSourceAccessorpotentially falling back to the default translation or the plain enum name if configured.Returns all potentially translated values for the givenEnumtype.voidsetEnableDefaultTranslation(boolean enableDefaultTranslation) voidsetParseEnumNameAsFallback(boolean parseEnumNameAsFallback)
-
Constructor Details
-
EnumTranslator
public EnumTranslator(org.springframework.hateoas.mediatype.MessageResolver resolver) Creates a newEnumTranslatorusing the givenMessageSourceAccessor.- Parameters:
resolver- must not be null.
-
-
Method Details
-
setEnableDefaultTranslation
public void setEnableDefaultTranslation(boolean enableDefaultTranslation) - Specified by:
setEnableDefaultTranslationin interfaceEnumTranslationConfiguration
-
setParseEnumNameAsFallback
public void setParseEnumNameAsFallback(boolean parseEnumNameAsFallback) - Specified by:
setParseEnumNameAsFallbackin interfaceEnumTranslationConfiguration
-
asText
Resolves the given enum value into aStringconsulting the configuredMessageSourceAccessorpotentially falling back to the default translation if configured. Returning the plain enum name if no resolution applies.- Parameters:
value- must not be null.- Returns:
-
getValues
Returns all potentially translated values for the givenEnumtype.- Parameters:
type- must not be null.- Returns:
-
fromText
Parses the given source text into the corresponding enum value using the configuredMessageSourceAccessorpotentially falling back to the default translation or the plain enum name if configured.- Parameters:
type- must not be null.text- can be null- Returns:
- the resolved enum or null if the resolution failed.
-