Class Deserializer

java.lang.Object
cz.metacentrum.perun.rpclib.api.Deserializer
Direct Known Subclasses:
JsonDeserializer

public abstract class Deserializer extends Object
Subclasses of Deserializer class provide methods to deserialize values supplied as name/value pairs in some form (ie. in JSON or as HTTP request parameters). It is presumed that the names of the values are unique - results are undefined if multiple values with the same name are supplied. Implementing any of the read* methods is optional.
Since:
0.1
Author:
Jan Klos <ddd@mail.muni.cz>
  • Constructor Details

    • Deserializer

      public Deserializer()
  • Method Details

    • contains

      public abstract boolean contains(String name)
      Returns true if value with the specified name is supplied.
      Parameters:
      name - name of the value to check
      Returns:
      true if value with the specified name is supplied, false otherwise
    • read

      public <T> T read(String name, Class<T> valueType)
      Reads value with the specified name as valueType.
      Parameters:
      name - name of the value to read
      valueType - type of the value to read
      Returns:
      the value as valueType
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
      RpcException - if the specified value cannot be parsed as valueType or if it is not supplied
    • read

      public <T> T read(Class<T> valueType)
      Reads value as valueType.
      Parameters:
      valueType - type of the value to read
      Returns:
      the value as valueType
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
      RpcException - if the specified value cannot be parsed as valueType or if it is not supplied
    • readArrayOfInts

      public int[] readArrayOfInts(String name)
    • readArrayOfInts

      public int[] readArrayOfInts()
    • readInt

      public abstract int readInt(String name)
      Reads value with the specified name as int.
      Parameters:
      name - name of the value to read
      Returns:
      the value as int
      Throws:
      RpcException - if the specified value cannot be parsed as int or if it is not supplied
    • readInt

      public abstract int readInt()
      Reads value as int.
      Returns:
      the value as int
      Throws:
      RpcException - if the specified value cannot be parsed as int or if it is not supplied
    • readList

      public <T> List<T> readList(String name, Class<T> valueType)
      Reads array with the specified name as List<valueType>.
      Parameters:
      name - name of the array to read
      valueType - type of the value to read
      Returns:
      the value as List<valueType>
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
      RpcException - if the specified value cannot be parsed as valueType or if it is not supplied
    • readList

      public <T> List<T> readList(Class<T> valueType)
      Reads an array List<valueType>.
      Parameters:
      valueType - type of the value to read
      Returns:
      the value as List<valueType>
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
      RpcException - if the specified value cannot be parsed as valueType or if it is not supplied
    • readString

      public abstract String readString(String name)
      Reads value with the specified name as String.
      Parameters:
      name - name of the value to read
      Returns:
      the value as String
      Throws:
      RpcException - If the specified value cannot be parsed as String or if it is not supplied
    • readString

      public abstract String readString()
      Reads value as String.
      Returns:
      the value as String
      Throws:
      RpcException - If the specified value cannot be parsed as String or if it is not supplied