Class MetaschemaJsonReader
- java.lang.Object
-
- gov.nist.secauto.metaschema.databind.io.json.MetaschemaJsonReader
-
- All Implemented Interfaces:
IParsingContext<com.fasterxml.jackson.core.JsonParser,IJsonProblemHandler>,IJsonParsingContext
public class MetaschemaJsonReader extends Object implements IJsonParsingContext
-
-
Constructor Summary
Constructors Constructor Description MetaschemaJsonReader(com.fasterxml.jackson.core.JsonParser parser)Construct a new Module-aware JSON parser using the default problem handler.MetaschemaJsonReader(com.fasterxml.jackson.core.JsonParser parser, IJsonProblemHandler problemHandler)Construct a new Module-aware JSON parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IJsonProblemHandlergetProblemHandler()A handler that provides callbacks used to resolve parsing issues.com.fasterxml.jackson.core.JsonParsergetReader()The parser used for reading data associated with the supported format.<T> Tread(IAssemblyClassBinding targetDefinition)Parses JSON into a bound object.voidreadDefinitionValue(IClassBinding targetDefinition, Object targetObject, Map<String,? extends IBoundNamedInstance> instances)Parse a JSON value described by the provideddefinition.protected booleanreadInstance(IBoundNamedInstance targetInstance, Object parentObject)Read the data associated with theinstanceand apply it to the providedparentObject.protected ObjectreadInstanceValue(IBoundNamedInstance instance, Object parentObject)Read the data associated with theinstance.
-
-
-
Constructor Detail
-
MetaschemaJsonReader
public MetaschemaJsonReader(@NonNull com.fasterxml.jackson.core.JsonParser parser)
Construct a new Module-aware JSON parser using the default problem handler.- Parameters:
parser- the JSON parser to parse with- See Also:
DefaultJsonProblemHandler
-
MetaschemaJsonReader
public MetaschemaJsonReader(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull IJsonProblemHandler problemHandler)
Construct a new Module-aware JSON parser.- Parameters:
parser- the JSON parser to parse withproblemHandler- the problem handler implementation to use
-
-
Method Detail
-
getReader
public com.fasterxml.jackson.core.JsonParser getReader()
Description copied from interface:IParsingContextThe parser used for reading data associated with the supported format.- Specified by:
getReaderin interfaceIParsingContext<com.fasterxml.jackson.core.JsonParser,IJsonProblemHandler>- Returns:
- the parser
-
getProblemHandler
public IJsonProblemHandler getProblemHandler()
Description copied from interface:IParsingContextA handler that provides callbacks used to resolve parsing issues.- Specified by:
getProblemHandlerin interfaceIParsingContext<com.fasterxml.jackson.core.JsonParser,IJsonProblemHandler>- Returns:
- the configured handler
-
read
@Nullable public <T> T read(@NonNull IAssemblyClassBinding targetDefinition) throws IOException
Parses JSON into a bound object. This assembly must be a root assembly for which a call toIAssemblyDefinition.isRoot()will returntrue.This method expects the parser's current token to be:
nullindicating that the parser has not yet parsed a JSON node;- a
JsonToken.START_OBJECTwhich represents the object wrapper containing the root field, - a
JsonToken.FIELD_NAMErepresenting the root field to parse, or - a peer field to the root field that will be handled by the
IJsonProblemHandler.handleUnknownProperty(IClassBinding, Object, String, IJsonParsingContext)method.
After parsing the current token will be:
- the next token after the
JsonToken.END_OBJECTcorresponding to the initialJsonToken.START_OBJECTparsed by this method; - the next token after the
JsonToken.END_OBJECTfor the root field's value; or - the next token after all fields and associated values have been parsed
looking for the root field. This next token will be the
JsonToken.END_OBJECTfor the object containing the fields. In this case the method will throw anIOExceptionindicating the root was not found.
- Type Parameters:
T- the Java type of the resulting bound instance- Parameters:
targetDefinition- the definition describing the root element data to parse- Returns:
- the bound object instance representing the JSON object
- Throws:
IOException- if an error occurred while parsing the JSON
-
readInstance
protected boolean readInstance(@NonNull IBoundNamedInstance targetInstance, @NonNull Object parentObject) throws IOException
Read the data associated with theinstanceand apply it to the providedparentObject.Consumes the field if the field's name matches. If it matches, then
trueis returned after parsing the value. Otherwise,falseis returned to indicate the property was not parsed.- Parameters:
targetInstance- the instance to parse data forparentObject- the Java object that data parsed by this method will be stored in- Returns:
trueif the instance was parsed, orfalseif the data did not contain information for this instance- Throws:
IOException- if an error occurred while parsing the data
-
readInstanceValue
protected Object readInstanceValue(@NonNull IBoundNamedInstance instance, @NonNull Object parentObject) throws IOException
Read the data associated with theinstance.- Parameters:
instance- the instance that describes the syntax of the data to readparentObject- the Java object that data parsed by this method will be stored in- Returns:
- the parsed value(s)
- Throws:
IOException- if an error occurred while parsing the input
-
readDefinitionValue
public void readDefinitionValue(IClassBinding targetDefinition, Object targetObject, Map<String,? extends IBoundNamedInstance> instances) throws IOException
Description copied from interface:IJsonParsingContextParse a JSON value described by the provideddefinition.- Specified by:
readDefinitionValuein interfaceIJsonParsingContext- Parameters:
targetDefinition- the bound Module definition describing the structure of the JSON data to parsetargetObject- the Java object that will contain this datainstances- the set of named instances to read- Throws:
IOException- if an error occurred while parsing the JSON
-
-