Class StringToEnumDecoder

java.lang.Object
com.vaadin.flow.server.communication.rpc.StringToEnumDecoder
All Implemented Interfaces:
RpcDecoder, Serializable

public class StringToEnumDecoder extends Object implements RpcDecoder
Decodes a JsonValue with JsonType.STRING type to Enum subclass type.

This decoder is applicable to any JsonValue which is JsonString and any Enum sublcass

For internal use only. May be renamed or removed in a future release.

Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • StringToEnumDecoder

      public StringToEnumDecoder()
  • Method Details

    • isApplicable

      public boolean isApplicable(elemental.json.JsonValue value, Class<?> type)
      Description copied from interface: RpcDecoder
      Returns true if the decoder is applicable for the given value and the required type.
      Specified by:
      isApplicable in interface RpcDecoder
      Parameters:
      value - the value which needs to be decoded
      type - the required type to decode
      Returns:
      true if this decoder is able to decode the value to the type, false otherwise
    • decode

      public <T> T decode(elemental.json.JsonValue value, Class<T> type) throws RpcDecodeException
      Description copied from interface: RpcDecoder
      Decode the given value to the required type.

      RpcDecodeException is thrown if the value cannot be converted to the type (even though the decoder is applicable for the value and the type).

      Specified by:
      decode in interface RpcDecoder
      Type Parameters:
      T - the decoded value type
      Parameters:
      value - the value which needs to be decoded
      type - the required type to decode
      Returns:
      the decoded value
      Throws:
      RpcDecodeException - if the value cannot be converted to the type