Package co.arago.util.json.path
Class GetByJsonPath
- java.lang.Object
-
- co.arago.util.json.path.GetByJsonPath
-
public class GetByJsonPath extends java.lang.ObjectGet an arbitrary field from any Object by using a JsonPath. The Object must be convertable to a String viaJsonTools.toString(Object).This class is a simplification of
JsonPathParser.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringjsonPath
-
Constructor Summary
Constructors Modifier Constructor Description protectedGetByJsonPath(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.Objectget(java.lang.Object jsonObject)Get as simple Object<T> Tget(java.lang.Object jsonObject, java.lang.Class<T> clazz)Get as Object of Class Tjava.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 Tstatic GetByJsonPathnewWith(java.lang.String jsonPath)Static constructor.static GetByJsonPathnewWith(java.lang.String jsonPath, co.arago.util.json.JsonTools jsonTools)Static constructor.
-
-
-
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 usejsonTools- 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.
-
-