Class JsonDeserializer

java.lang.Object
cz.metacentrum.perun.rpc.deserializer.Deserializer
cz.metacentrum.perun.rpc.deserializer.JsonDeserializer

public class JsonDeserializer extends Deserializer
Deserializer for JSON / JSONP data format.

Reads parameters from body (InputStream) of request which is typically POST. Doesn't read any parameters form URL!

While deserializing objects from JSON some of their properties may be ignored. They are not read from input and also not required to be present in input in order to match JSON object to the right Java object. They are set as NULL in Java object (if present as variable) or ignored at all.

Author:
Jan Klos invalid input: '<'ddd@mail.muni.cz>, Pavel Zlamal invalid input: '<'256627@mail.muni.cz>
  • Constructor Details

    • JsonDeserializer

      public JsonDeserializer(jakarta.servlet.http.HttpServletRequest request) throws IOException
      Create deserializer for JSON/JSONP data format.
      Parameters:
      request - HttpServletRequest this deserializer is about to process
      Throws:
      IOException - if an IO error occurs
      RpcException - if content of in is wrongly formatted
    • JsonDeserializer

      public JsonDeserializer(InputStream in) throws IOException
      Throws:
      IOException
  • Method Details

    • contains

      public boolean contains(String name)
      Description copied from class: Deserializer
      Returns true if value with the specified name is supplied.
      Specified by:
      contains in class Deserializer
      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()
      Description copied from class: Deserializer
      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.

      Overrides:
      getServletRequest in class Deserializer
      Returns:
      HttpServletRequest related to concrete call
    • read

      public <T> T read(Class<T> valueType)
      Description copied from class: Deserializer
      Reads value from root Json node.
      Overrides:
      read in class Deserializer
      Parameters:
      valueType - type of the value to read
      Returns:
      the value as valueType
    • read

      public <T> T read(String name, Class<T> valueType)
      Description copied from class: Deserializer
      Reads value with the specified name as valueType.
      Overrides:
      read in class Deserializer
      Parameters:
      name - name of the value to read
      valueType - type of the value to read
      Returns:
      the value as valueType
    • readAll

      public String readAll()
      Description copied from class: Deserializer
      Returns string representation of the variables stored in the deserializer.
      Specified by:
      readAll in class Deserializer
      Returns:
      string containing all variables
    • readArrayOfInts

      public int[] readArrayOfInts(String name)
      Overrides:
      readArrayOfInts in class Deserializer
    • readBoolean

      public Boolean readBoolean(String name)
      Description copied from class: Deserializer
      Reads value with the specified name as Boolean.
      Specified by:
      readBoolean in class Deserializer
      Parameters:
      name - name of the value to read
      Returns:
      the value as Boolean
    • readInt

      public int readInt(String name)
      Description copied from class: Deserializer
      Reads value with the specified name as int.
      Specified by:
      readInt in class Deserializer
      Parameters:
      name - name of the value to read
      Returns:
      the value as int
    • readList

      public <T> List<T> readList(Class<T> valueType)
      Description copied from class: Deserializer
      Reads array from root Json node.
      Overrides:
      readList in class Deserializer
      Parameters:
      valueType - type of the value to read
      Returns:
      the value as List<valueType>
    • readList

      public <T> List<T> readList(String name, Class<T> valueType)
      Description copied from class: Deserializer
      Reads array with the specified name as List<valueType>.
      Overrides:
      readList in class Deserializer
      Parameters:
      name - name of the array to read
      valueType - type of the value to read
      Returns:
      the value as List<valueType>
    • readListPerunBeans

      public List<PerunBean> readListPerunBeans(String name)
      Description copied from class: Deserializer
      Reads array with the specified name as List<PerunBean>.
      Overrides:
      readListPerunBeans in class Deserializer
      Parameters:
      name - name of the array to read
      Returns:
      the value as List<PerunBean>
    • readPerunBean

      public PerunBean readPerunBean(String name)
      Description copied from class: Deserializer
      Reads value with the specified name as PerunBean.
      Overrides:
      readPerunBean in class Deserializer
      Parameters:
      name - name of the value to read
      Returns:
      the value as PerunBean
    • readString

      public String readString(String name)
      Description copied from class: Deserializer
      Reads value with the specified name as String.
      Specified by:
      readString in class Deserializer
      Parameters:
      name - name of the value to read
      Returns:
      the value as String
    • readUUID

      public UUID readUUID(String name)
      Description copied from class: Deserializer
      Reads value with the specified name as UUID.
      Specified by:
      readUUID in class Deserializer
      Parameters:
      name - name of the value to read
      Returns:
      the value as UUID