java.lang.Object
org.springframework.data.rest.webmvc.json.EnumTranslator
All Implemented Interfaces:
org.springframework.data.rest.core.config.EnumTranslationConfiguration

public class EnumTranslator extends Object implements org.springframework.data.rest.core.config.EnumTranslationConfiguration
Configuration to tweak enum serialization.
Author:
Oliver Gierke
  • Constructor Details

  • Method Details

    • setEnableDefaultTranslation

      public void setEnableDefaultTranslation(boolean enableDefaultTranslation)
      Specified by:
      setEnableDefaultTranslation in interface org.springframework.data.rest.core.config.EnumTranslationConfiguration
    • setParseEnumNameAsFallback

      public void setParseEnumNameAsFallback(boolean parseEnumNameAsFallback)
      Specified by:
      setParseEnumNameAsFallback in interface org.springframework.data.rest.core.config.EnumTranslationConfiguration
    • asText

      public String asText(Enum<?> value)
      Resolves the given enum value into a String consulting the configured MessageSourceAccessor potentially 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

      public List<String> getValues(Class<? extends Enum<?>> type)
      Returns all potentially translated values for the given Enum type.
      Parameters:
      type - must not be null.
      Returns:
    • fromText

      public <T extends Enum<?>> T fromText(Class<T> type, String text)
      Parses the given source text into the corresponding enum value using the configured MessageSourceAccessor potentially 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.