Class GetByJsonPath


  • public class GetByJsonPath
    extends java.lang.Object
    Get an arbitrary field from any Object by using a JsonPath. The Object must be convertable to a String via JsonTools.toString(Object).

    This class is a simplification of JsonPathParser.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String jsonPath  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected GetByJsonPath​(java.lang.String jsonPath, co.arago.util.json.JsonTools jsonTools)
      Protected constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get​(java.lang.Object jsonObject)
      Get as simple Object
      <T> T get​(java.lang.Object jsonObject, java.lang.Class<T> clazz)
      Get as Object of Class T
      java.util.Collection<java.lang.Object> getAll​(java.lang.Object jsonObject)
      Get all as Collection of Objects
      <T> java.util.Collection<T> getAll​(java.lang.Object jsonObject, java.lang.Class<T> clazz)
      Get all as Collection of Objects of Class T
      static GetByJsonPath newWith​(java.lang.String jsonPath)
      Static constructor.
      static GetByJsonPath newWith​(java.lang.String jsonPath, co.arago.util.json.JsonTools jsonTools)
      Static constructor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • jsonPath

        protected final java.lang.String jsonPath
    • Constructor Detail

      • GetByJsonPath

        protected GetByJsonPath​(java.lang.String jsonPath,
                                co.arago.util.json.JsonTools jsonTools)
        Protected constructor.

        Use newWith(String) or newWith(String, JsonTools).

        Parameters:
        jsonPath - The jsonPath to use
        jsonTools - The specific jsonTools to use
    • Method Detail

      • newWith

        public static GetByJsonPath newWith​(java.lang.String jsonPath)
        Static constructor. Uses JsonUtil.DEFAULT.
        Parameters:
        jsonPath - The jsonPath to use
        Returns:
        New instance of GetByJsonPath
      • newWith

        public static GetByJsonPath newWith​(java.lang.String jsonPath,
                                            co.arago.util.json.JsonTools jsonTools)
        Static constructor.
        Parameters:
        jsonPath - The jsonPath to use
        jsonTools - The specific jsonTools to use
        Returns:
        New instance of GetByJsonPath
      • get

        public java.lang.Object get​(java.lang.Object jsonObject)
        Get as simple Object
        Parameters:
        jsonObject - Object the jsonPath is applied to.
        Returns:
        The jsonObject found or null.
        Throws:
        org.jsfr.json.exception.JsonSurfingException - When the object cannot be transformed into a Json string.
      • get

        public <T> T get​(java.lang.Object jsonObject,
                         java.lang.Class<T> clazz)
        Get as Object of Class T
        Type Parameters:
        T - Type of the result.
        Parameters:
        jsonObject - Object the jsonPath is applied to.
        clazz - The class of the desired result.
        Returns:
        The jsonObject found or null.
        Throws:
        org.jsfr.json.exception.JsonSurfingException - When the object cannot be transformed into a Json string.
      • getAll

        public java.util.Collection<java.lang.Object> getAll​(java.lang.Object jsonObject)
        Get all as Collection of Objects
        Parameters:
        jsonObject - Object the jsonPath is applied to.
        Returns:
        The list of Objects found.
        Throws:
        org.jsfr.json.exception.JsonSurfingException - When the object cannot be transformed into a Json string.
      • getAll

        public <T> java.util.Collection<T> getAll​(java.lang.Object jsonObject,
                                                  java.lang.Class<T> clazz)
        Get all as Collection of Objects of Class T
        Type Parameters:
        T - Type of the result.
        Parameters:
        jsonObject - Object the jsonPath is applied to.
        clazz - The class of the desired result.
        Returns:
        The list of Objects found.
        Throws:
        org.jsfr.json.exception.JsonSurfingException - When the object cannot be transformed into a Json string.