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 IJsonProblemHandler
getProblemHandler()
A handler that provides callbacks used to resolve parsing issues.com.fasterxml.jackson.core.JsonParser
getReader()
The parser used for reading data associated with the supported format.<T> T
read(IAssemblyClassBinding targetDefinition)
Parses JSON into a bound object.void
readDefinitionValue(IClassBinding targetDefinition, Object targetObject, Map<String,? extends IBoundNamedInstance> instances)
Parse a JSON value described by the provideddefinition
.protected boolean
readInstance(IBoundNamedInstance targetInstance, Object parentObject)
Read the data associated with theinstance
and apply it to the providedparentObject
.protected Object
readInstanceValue(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:IParsingContext
The parser used for reading data associated with the supported format.- Specified by:
getReader
in interfaceIParsingContext<com.fasterxml.jackson.core.JsonParser,IJsonProblemHandler>
- Returns:
- the parser
-
getProblemHandler
public IJsonProblemHandler getProblemHandler()
Description copied from interface:IParsingContext
A handler that provides callbacks used to resolve parsing issues.- Specified by:
getProblemHandler
in 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:
null
indicating that the parser has not yet parsed a JSON node;- a
JsonToken.START_OBJECT
which represents the object wrapper containing the root field, - a
JsonToken.FIELD_NAME
representing 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_OBJECT
corresponding to the initialJsonToken.START_OBJECT
parsed by this method; - the next token after the
JsonToken.END_OBJECT
for 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_OBJECT
for the object containing the fields. In this case the method will throw anIOException
indicating 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 theinstance
and apply it to the providedparentObject
.Consumes the field if the field's name matches. If it matches, then
true
is returned after parsing the value. Otherwise,false
is 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:
true
if the instance was parsed, orfalse
if 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:IJsonParsingContext
Parse a JSON value described by the provideddefinition
.- Specified by:
readDefinitionValue
in 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
-
-