Package co.arago.util.json.path
Class JsonPathParser
- java.lang.Object
-
- co.arago.util.json.AbstractJsonParser
-
- co.arago.util.json.path.JsonPathParser
-
public class JsonPathParser extends AbstractJsonParser
Wrapper around the mechanics of theJsonSurferTool.getJsonSurfer()for parsing data via JsonPaths.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJsonPathParser.Builderstatic classJsonPathParser.Conf<T extends JsonPathParser.Conf<T>>
-
Field Summary
-
Fields inherited from class co.arago.util.json.AbstractJsonParser
jsonCuts, jsonSurferTool
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonPathParser(JsonPathParser.Conf<?> builder)Protected constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckDataField()java.util.Map<java.lang.String,java.util.Collection<java.lang.Object>>getAllFromAllPaths(java.lang.Object jsonObject)Get all matching values from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].<C> java.util.Map<java.lang.String,java.util.Collection<C>>getAllFromAllPaths(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get all matching values from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].java.util.Collection<java.lang.Object>getAllFromOnePath(java.lang.Object jsonObject)Get all matching values from one path inAbstractJsonParser.jsonCuts[jsonPath, name].<C> java.util.Collection<C>getAllFromOnePath(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get all matching values from one path inAbstractJsonParser.jsonCuts[jsonPath, name].protected <C> java.util.Map<java.lang.String,java.util.Collection<C>>getAllValues(org.jsfr.json.Collector collector, java.lang.Class<C> clazz)Get all values for each entry inAbstractJsonParser.jsonCuts.protected org.jsfr.json.CollectorgetCollector(java.lang.Object input)Get a matchingCollectorfrom the type of the input.java.util.Map<java.lang.String,java.lang.Object>getOneFromAllPaths(java.lang.Object jsonObject)Get one value from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].<C> java.util.Map<java.lang.String,C>getOneFromAllPaths(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get one value from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].java.lang.ObjectgetOneFromOnePath(java.lang.Object jsonObject)Get one value from one path inAbstractJsonParser.jsonCuts[jsonPath, name].<C> CgetOneFromOnePath(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get one value from one path inAbstractJsonParser.jsonCuts[jsonPath, name].protected <C> java.util.Map<java.lang.String,C>getOneValues(org.jsfr.json.Collector collector, java.lang.Class<C> clazz)Get one value for each entry inAbstractJsonParser.jsonCuts.static JsonPathParser.Conf<?>newBuilder()Get a new Builder
-
-
-
Constructor Detail
-
JsonPathParser
protected JsonPathParser(JsonPathParser.Conf<?> builder)
Protected constructor.- Parameters:
builder- Builder for this class.- See Also:
newBuilder()
-
-
Method Detail
-
newBuilder
public static JsonPathParser.Conf<?> newBuilder()
Get a new Builder- Returns:
- New Builder instance.
-
getCollector
protected org.jsfr.json.Collector getCollector(java.lang.Object input)
Get a matchingCollectorfrom the type of the input.- Parameters:
input- Any input type.- Returns:
- The matching collector for the input.
- Throws:
org.jsfr.json.exception.JsonSurfingException- When the input cannot be parsed into a Json String.
-
getOneValues
protected <C> java.util.Map<java.lang.String,C> getOneValues(org.jsfr.json.Collector collector, java.lang.Class<C> clazz)Get one value for each entry inAbstractJsonParser.jsonCuts.- Type Parameters:
C- Type of value- Parameters:
collector- The collector to use.clazz- Type of the result values in the returned map.- Returns:
- A map with Tuple [name, value] where value is one found by the matching key (json path) of
AbstractJsonParser.jsonCuts.
-
getAllValues
protected <C> java.util.Map<java.lang.String,java.util.Collection<C>> getAllValues(org.jsfr.json.Collector collector, java.lang.Class<C> clazz)Get all values for each entry inAbstractJsonParser.jsonCuts.- Type Parameters:
C- Type of value- Parameters:
collector- The collector to use.clazz- Type of the result values in the returned map.- Returns:
- A map with Tuple [name, collection of values] where values are a collection of all found by the matching
key (json path) of
AbstractJsonParser.jsonCuts.
-
checkDataField
protected void checkDataField()
- Throws:
java.lang.IllegalArgumentException- WhenAbstractJsonParser.jsonCutsis empty but at least one entry is needed.
-
getOneFromOnePath
public java.lang.Object getOneFromOnePath(java.lang.Object jsonObject)
Get one value from one path inAbstractJsonParser.jsonCuts[jsonPath, name].- Parameters:
jsonObject- The object to parse.- Returns:
- The value found or null if nothing can be found.
-
getOneFromOnePath
public <C> C getOneFromOnePath(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get one value from one path inAbstractJsonParser.jsonCuts[jsonPath, name].- Type Parameters:
C- Type of result values.- Parameters:
jsonObject- The object to parse.clazz- Class of result values.- Returns:
- The value found or null if nothing can be found.
-
getOneFromAllPaths
public java.util.Map<java.lang.String,java.lang.Object> getOneFromAllPaths(java.lang.Object jsonObject)
Get one value from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].- Parameters:
jsonObject- The object to parse.- Returns:
- Map of [name, the value found].
-
getOneFromAllPaths
public <C> java.util.Map<java.lang.String,C> getOneFromAllPaths(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get one value from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].- Type Parameters:
C- Type of result values.- Parameters:
jsonObject- The object to parse.clazz- Class of result values.- Returns:
- Map of [name, the value found].
-
getAllFromOnePath
public java.util.Collection<java.lang.Object> getAllFromOnePath(java.lang.Object jsonObject)
Get all matching values from one path inAbstractJsonParser.jsonCuts[jsonPath, name].- Parameters:
jsonObject- The object to parse.- Returns:
- Collection of found values.
-
getAllFromOnePath
public <C> java.util.Collection<C> getAllFromOnePath(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get all matching values from one path inAbstractJsonParser.jsonCuts[jsonPath, name].- Type Parameters:
C- Type of result values.- Parameters:
jsonObject- The object to parse.clazz- Class of result values.- Returns:
- Collection of found values.
-
getAllFromAllPaths
public java.util.Map<java.lang.String,java.util.Collection<java.lang.Object>> getAllFromAllPaths(java.lang.Object jsonObject)
Get all matching values from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].- Parameters:
jsonObject- The object to parse.- Returns:
- Map of [name, Collection of found values].
-
getAllFromAllPaths
public <C> java.util.Map<java.lang.String,java.util.Collection<C>> getAllFromAllPaths(java.lang.Object jsonObject, java.lang.Class<C> clazz)Get all matching values from all paths inAbstractJsonParser.jsonCuts[jsonPath, name].- Type Parameters:
C- Type of result values.- Parameters:
jsonObject- The object to parse.clazz- Class of result values.- Returns:
- Map of [name, Collection of found values].
-
-