Class Deserializer

java.lang.Object
cz.metacentrum.perun.rpc.deserializer.Deserializer
Direct Known Subclasses:
JsonDeserializer, UrlDeserializer

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.
Author:
Jan Klos invalid input: '<'ddd@mail.muni.cz>, Pavel Zlamal invalid input: '<'256627@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
    • getServletRequest

      public jakarta.servlet.http.HttpServletRequest getServletRequest()
      Return HttpServletRequest related to concrete call this deserializer is used to process.

      Note that this "request" is not necessarily used as source to read parameters by other methods of deserializer. It IS typically for GET requests, but NOT for POST with JSON/JSONP data format.

      Returns:
      HttpServletRequest related to concrete call
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
    • 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 from root Json node.
      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
    • readAll

      public abstract String readAll()
      Returns string representation of the variables stored in the deserializer.
      Returns:
      string containing all variables
      Throws:
      RpcException
    • readArrayOfInts

      public int[] readArrayOfInts(String name)
    • readBoolean

      public abstract Boolean readBoolean(String name)
      Reads value with the specified name as Boolean.
      Parameters:
      name - name of the value to read
      Returns:
      the value as Boolean
      Throws:
      RpcException - If the specified value cannot be parsed as String or if it is not supplied
    • 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
    • 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 array from root Json node.
      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
    • readListPerunBeans

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

      public LocalDate readLocalDate(String name)
      Reads LocalDate value with the specified name. Expected ISO-8601 format. (yyyy-MM-dd)
      Parameters:
      name - name of the localDate value
      Returns:
      parsed local date
    • readPerunBean

      public PerunBean readPerunBean(String name)
      Reads value with the specified name as PerunBean.
      Parameters:
      name - name of the value to read
      Returns:
      the value as PerunBean
      Throws:
      UnsupportedOperationException - if this deserializer does not implement this method
      RpcException - if the specified value cannot be parsed as perunBean 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
    • readUUID

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

      public void stateChangingCheck()
      Check whether method that changes state is not GET.
      Throws:
      RpcException - if method is GET