Class JsonInputParser.JsonParseResult
- java.lang.Object
-
- de.iip_ecosphere.platform.connectors.parser.JsonInputParser.JsonParseResult
-
- All Implemented Interfaces:
InputParser.ParseResult<com.jsoniter.any.Any>
- Enclosing class:
- JsonInputParser
public static final class JsonInputParser.JsonParseResult extends java.lang.Object implements InputParser.ParseResult<com.jsoniter.any.Any>
Defines a parse result instance for JSON.- Author:
- Holger Eichelberger, SSE
-
-
Field Summary
Fields Modifier and Type Field Description private com.jsoniter.any.Anyanyprivate byte[]dataprivate JsonInputParser.JsonParseResultparent
-
Constructor Summary
Constructors Modifier Constructor Description privateJsonParseResult(byte[] data)Creates a parse result instance.privateJsonParseResult(byte[] data, com.jsoniter.any.Any any, JsonInputParser.JsonParseResult parent)Creates a parse result instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private com.jsoniter.any.AnydataToAny()Turnsdatato any considering its "type".private com.jsoniter.any.AnydeserializeIfString(com.jsoniter.any.Any tmp)Deserializestmpif it looks like a string.private com.jsoniter.any.Any.EntryIteratorfindBy(int index)Searches for the entry at positionindex.private com.jsoniter.any.Any.EntryIteratorfindBy(int[] indexes)Returns an entry iterator to the element denoted by (nested)indexes.private com.jsoniter.any.Anyget(java.lang.String name, int... indexes)Returns the JSON object representingnameorindexes.intgetArraySize()If the actual element is an array, return the size.voidgetData(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> ifPresent, java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.com.jsoniter.any.AnygetData(java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.intgetDataCount()Returns the number of parsed data fields.java.lang.StringgetFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> valueCons, int... indexes)Returns the name of the field.private com.jsoniter.any.AnygetLocal(java.lang.String name, int[] indexes)Returns the JSON object representingnameorindexeswithout hierarchical name interpretation.voidgetLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> ifPresent, java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.com.jsoniter.any.AnygetLocalData(java.lang.String name, int... indexes)Returns the value of the data field for the given fieldnameor with via the givenindex.private byte[]getTopData()Returns the original input data array from the top-level parser result.JsonInputParser.JsonParseResultstepInto(java.lang.String name, int index)Sets the hierarchical substructure denoted bynameas current scope for further resolution.JsonInputParser.JsonParseResultstepOut()Steps out of the actual context set byInputParser.ParseResult.stepInto(String, int).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.iip_ecosphere.platform.connectors.parser.InputParser.ParseResult
getFieldName
-
-
-
-
Field Detail
-
any
private com.jsoniter.any.Any any
-
data
private byte[] data
-
parent
private JsonInputParser.JsonParseResult parent
-
-
Constructor Detail
-
JsonParseResult
private JsonParseResult(byte[] data)
Creates a parse result instance.- Parameters:
data- the data to parse/deserialize
-
JsonParseResult
private JsonParseResult(byte[] data, com.jsoniter.any.Any any, JsonInputParser.JsonParseResult parent)Creates a parse result instance.- Parameters:
data- the data to parse/deserializeany- the jsoniter object representing the contextparent- the parent parse result to jump back to instepOut().
-
-
Method Detail
-
getDataCount
public int getDataCount()
Description copied from interface:InputParser.ParseResultReturns the number of parsed data fields.- Specified by:
getDataCountin interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Returns:
- the number of data fields (non-negative)
-
getFieldName
public java.lang.String getFieldName(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> valueCons, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the name of the field. This operation may not be efficient on all input parsers, in particular if no index positions are recorded. However, for generically parsing back some structures, this operation is required.- Specified by:
getFieldNamein interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
valueCons- a value consumer to handle the value of the field (if found) in the same step, may be null for noneindexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the name of the field or empty if not known
- Throws:
java.io.IOException- if applyingvalueConsleads to an exception
-
findBy
private com.jsoniter.any.Any.EntryIterator findBy(int[] indexes)
Returns an entry iterator to the element denoted by (nested)indexes.- Parameters:
indexes- the path of (nested) 0-based indexes to the field, the sum must be less thangetDataCount()- Returns:
- the input iterator, null for not found
-
deserializeIfString
private com.jsoniter.any.Any deserializeIfString(com.jsoniter.any.Any tmp)
Deserializestmpif it looks like a string.- Parameters:
tmp- the any to be considered- Returns:
tmpor deserialized any
-
dataToAny
private com.jsoniter.any.Any dataToAny()
Turnsdatato any considering its "type".- Returns:
- any from
data
-
findBy
private com.jsoniter.any.Any.EntryIterator findBy(int index)
Searches for the entry at positionindex.- Parameters:
index- the index to search for- Returns:
- the entry iterator pointing to the index or null for none
-
getData
public com.jsoniter.any.Any getData(java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface.- Specified by:
getDatain interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
name- the name of the data field, may contain hierarchical names separated byInputParser.SEPARATOR, may be based on the scope set byInputParser.ParseResult.stepInto(String, int)indexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the data value
- Throws:
java.io.IOException- if the mapped index or the givenindex<0 || index >=InputParser.ParseResult.getDataCount()
-
get
private com.jsoniter.any.Any get(java.lang.String name, int... indexes)Returns the JSON object representingnameorindexes.- Parameters:
name- the name of the data field, may contain hierarchical names separated byInputParser.SEPARATOR, may be based on the scope set bystepInto(String, int)indexes- the path of (nested) 0-based indexes to the field, the sum must be less thangetDataCount()- Returns:
- the JSON object, may be null for not found
-
getData
public void getData(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> ifPresent, java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. Names may be hierarchical. May be overridden if direct access to names is provided by the parsed structure, e.g., in JSON. Thus, no index-access is provided in the first place by this interface. This method shall not throw any exception.- Specified by:
getDatain interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
ifPresent- consumer called if a data value was found. The value is passed toifPresentfor further processingname- the name of the data field, may contain hierarchical names separated byInputParser.SEPARATOR, may be based on the scope set byInputParser.ParseResult.stepInto(String, int)indexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Throws:
java.io.IOException- if an
-
getLocal
private com.jsoniter.any.Any getLocal(java.lang.String name, int[] indexes)Returns the JSON object representingnameorindexeswithout hierarchical name interpretation.- Parameters:
name- the name of the data fieldindexes- the path of (nested) 0-based indexes to the field, the sum must be less thangetDataCount()- Returns:
- the JSON object, may be null for not found
-
getLocalData
public com.jsoniter.any.Any getLocalData(java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination withInputParser.ParseResult.stepInto(String, int), this method shall be faster thanInputParser.ParseResult.getData(String, int...).- Specified by:
getLocalDatain interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
name- the name of the data fieldindexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the data value
- Throws:
java.io.IOException- if the mapped index or the givenindex<0 || index >=InputParser.ParseResult.getDataCount()
-
getLocalData
public void getLocalData(de.iip_ecosphere.platform.support.function.IOConsumer<com.jsoniter.any.Any> ifPresent, java.lang.String name, int... indexes) throws java.io.IOExceptionDescription copied from interface:InputParser.ParseResultReturns the value of the data field for the given fieldnameor with via the givenindex. Primary index goes via name and if not given/mapped, index-based access shall be used as fallback. No hierarchical name interpretation happens here (local). In combination withInputParser.ParseResult.stepInto(String, int), this method shall be faster thanInputParser.ParseResult.getData(IOConsumer, String, int...).- Specified by:
getLocalDatain interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
ifPresent- consumer called if a data value was found. The value is passed toifPresentfor further processingname- the name of the data fieldindexes- the path of (nested) 0-based indexes to the field, the sum must be less thanInputParser.ParseResult.getDataCount()- Throws:
java.io.IOException- if an exception occurred inifPresent
-
stepInto
public JsonInputParser.JsonParseResult stepInto(java.lang.String name, int index) throws java.io.IOException
Description copied from interface:InputParser.ParseResultSets the hierarchical substructure denoted bynameas current scope for further resolution. When overriding, declare the actual type as result type.- Specified by:
stepIntoin interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Parameters:
name- non-hierarchical name of contained substructureindex- the 0-based indexes to the field, must be less thanInputParser.ParseResult.getDataCount()- Returns:
- the sub parse-result taking
nameas context, use#stepOut()to leave that context - Throws:
java.io.IOException- if stepping into fails for some reason
-
getTopData
private byte[] getTopData()
Returns the original input data array from the top-level parser result.- Returns:
- the data
-
stepOut
public JsonInputParser.JsonParseResult stepOut()
Description copied from interface:InputParser.ParseResultSteps out of the actual context set byInputParser.ParseResult.stepInto(String, int). When overriding, declare the actual type as result type.- Specified by:
stepOutin interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Returns:
- the actual (parent) context, may be null if this step out was illegal in a non-nested context
-
getArraySize
public int getArraySize()
Description copied from interface:InputParser.ParseResultIf the actual element is an array, return the size.- Specified by:
getArraySizein interfaceInputParser.ParseResult<com.jsoniter.any.Any>- Returns:
- the size, may be negative
-
-