Class JsonParser

java.lang.Object
org.cyclonedx.CycloneDxSchema
org.cyclonedx.parsers.JsonParser
All Implemented Interfaces:
Parser

public class JsonParser extends CycloneDxSchema implements Parser
JsonParser is responsible for validating and parsing CycloneDX bill-of-material JSON documents and returning a Bom object.
Since:
3.0.0
  • Constructor Details

    • JsonParser

      public JsonParser()
  • Method Details

    • parse

      public Bom parse(File file) throws ParseException
      Parses a CycloneDX BOM.
      Specified by:
      parse in interface Parser
      Parameters:
      file - a File to parse
      Returns:
      a Bom object
      Throws:
      ParseException - when errors are encountered
    • parse

      public Bom parse(byte[] bomBytes) throws ParseException
      Parses a CycloneDX BOM.
      Specified by:
      parse in interface Parser
      Parameters:
      bomBytes - the byte array to parse
      Returns:
      a Bom object
      Throws:
      ParseException - when errors are encountered
    • parse

      public Bom parse(InputStream inputStream) throws ParseException
      Parses a CycloneDX BOM.
      Specified by:
      parse in interface Parser
      Parameters:
      inputStream - the InputStream from which to parse
      Returns:
      a Bom object
      Throws:
      ParseException - when errors are encountered
    • parse

      public Bom parse(Reader reader) throws ParseException
      Parses a CycloneDX BOM.
      Specified by:
      parse in interface Parser
      Parameters:
      reader - the Reader from which to parse
      Returns:
      a Bom object
      Throws:
      ParseException - when errors are encountered
    • validate

      public List<ParseException> validate(File file) throws IOException
      Validates a CycloneDX BOM.
      Specified by:
      validate in interface Parser
      Parameters:
      file - the CycloneDX BOM file to validate
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(File file, Version schemaVersion) throws IOException
      Validates a CycloneDX BOM conforms to a specific specification version.
      Specified by:
      validate in interface Parser
      Parameters:
      file - the CycloneDX BOM file to validate
      schemaVersion - the schema version to validate against
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(byte[] bomBytes) throws IOException
      Validates a CycloneDX BOM.
      Specified by:
      validate in interface Parser
      Parameters:
      bomBytes - the byte array to validate
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(byte[] bomBytes, Version schemaVersion) throws IOException
      Validates a CycloneDX BOM conforms to a specific specification version.
      Specified by:
      validate in interface Parser
      Parameters:
      bomBytes - the byte array to validate
      schemaVersion - the schema version to validate against
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(Reader reader) throws IOException
      Validates a CycloneDX BOM.
      Specified by:
      validate in interface Parser
      Parameters:
      reader - the Reader from which to parse
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(Reader reader, Version schemaVersion) throws IOException
      Validates a CycloneDX BOM conforms to a specific specification version.
      Specified by:
      validate in interface Parser
      Parameters:
      reader - the Reader from which to parse
      schemaVersion - the schema version to validate against
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(InputStream inputStream) throws IOException
      Validates a CycloneDX BOM.
      Specified by:
      validate in interface Parser
      Parameters:
      inputStream - the InputStream from which to validate
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(InputStream inputStream, Version schemaVersion) throws IOException
      Validates a CycloneDX BOM conforms to a specific specification version.
      Specified by:
      validate in interface Parser
      Parameters:
      inputStream - the InputStream from which to validate
      schemaVersion - the schema version to validate against
      Returns:
      a List of ParseException. If the size of the list is 0, validation was successful
      Throws:
      IOException - when errors are encountered
    • validate

      public List<ParseException> validate(String bomString, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specification through JSON validation.
      Parameters:
      bomString - the CycloneDX BOM to validate
      schemaVersion - the schema version to validate against
      Returns:
      a list of exceptions encountered during validation
      Throws:
      IOException - when errors are encountered
      Since:
      3.0.0
    • validate

      public List<ParseException> validate(com.fasterxml.jackson.databind.JsonNode bomJson, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specification through JSON validation.
      Parameters:
      bomJson - the CycloneDX BOM to validate
      schemaVersion - the schema version to validate against
      Returns:
      a list of exceptions encountered during validation
      Throws:
      IOException - when errors are encountered
      Since:
      3.0.0
    • isValid

      public boolean isValid(File file) throws IOException
      Verifies a CycloneDX BOM conforms to the latest version of the specification.
      Specified by:
      isValid in interface Parser
      Parameters:
      file - the CycloneDX BOM file to validate
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(File file, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specified specification version.
      Specified by:
      isValid in interface Parser
      Parameters:
      file - the CycloneDX BOM file to validate
      schemaVersion - the schema version to validate against
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(byte[] bomBytes) throws IOException
      Verifies a CycloneDX BOM conforms to the latest version of the specification.
      Specified by:
      isValid in interface Parser
      Parameters:
      bomBytes - the byte array to validate
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(byte[] bomBytes, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specified specification version.
      Specified by:
      isValid in interface Parser
      Parameters:
      bomBytes - the byte array to validate
      schemaVersion - the schema version to validate against
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(Reader reader) throws IOException
      Verifies a CycloneDX BOM conforms to the latest version of the specification.
      Specified by:
      isValid in interface Parser
      Parameters:
      reader - the Reader from which to validate
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(Reader reader, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specified specification version.
      Specified by:
      isValid in interface Parser
      Parameters:
      reader - the Reader from which to validate
      schemaVersion - the schema version to validate against
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(InputStream inputStream) throws IOException
      Verifies a CycloneDX BOM conforms to the latest version of the specification.
      Specified by:
      isValid in interface Parser
      Parameters:
      inputStream - the InputStream from which to validate
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered
    • isValid

      public boolean isValid(InputStream inputStream, Version schemaVersion) throws IOException
      Verifies a CycloneDX BOM conforms to the specified specification version.
      Specified by:
      isValid in interface Parser
      Parameters:
      inputStream - the InputStream from which to validate
      schemaVersion - the schema version to validate against
      Returns:
      true if the file is a valid BOM, false if not
      Throws:
      IOException - when errors are encountered