Class MetaschemaJsonReader

    • 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 with
        problemHandler - the problem handler implementation to use
    • Method Detail

      • 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 to IAssemblyDefinition.isRoot() will return true.

        This method expects the parser's current token to be:

        After parsing the current token will be:

        • the next token after the JsonToken.END_OBJECT corresponding to the initial JsonToken.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 an IOException 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 the instance and apply it to the provided parentObject.

        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 for
        parentObject - the Java object that data parsed by this method will be stored in
        Returns:
        true if the instance was parsed, or false 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 the instance.
        Parameters:
        instance - the instance that describes the syntax of the data to read
        parentObject - 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