Skip to content

Deserializing OrganizationEntity fails when name is not set #507

@nscuro

Description

@nscuro

Trying to deserialize the following JSON BOM:

{
  "bomFormat": "CycloneDX",
  "specVersion": "1.6",
  "components": [
    {
      "type": "library",
      "name": "acme-library",
      "licenses": [
        {
          "license": {
            "name": "foo",
            "licensing": {
              "purchaser": {
                "organization": {
                  "contact": [
                    {
                      "name": ""
                    }
                  ]
                }
              }
            }
          }
        }
      ]
    }
  ]
}

Fails with:

Caused by: java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.JsonNode.asText()" because the return value of "com.fasterxml.jackson.databind.JsonNode.get(String)" is null
	at org.cyclonedx.util.deserializer.OrganizationalChoiceDeserializer.deserializeOrganization(OrganizationalChoiceDeserializer.java:54)
	at org.cyclonedx.util.deserializer.OrganizationalChoiceDeserializer.deserialize(OrganizationalChoiceDeserializer.java:45)
	at org.cyclonedx.util.deserializer.OrganizationalChoiceDeserializer.deserialize(OrganizationalChoiceDeserializer.java:32)

Because OrganizationalChoiceDeserializer assumes name to always be present, despite it not being a mandatory field according to the spec:

private OrganizationalEntity deserializeOrganization(JsonParser jp, JsonNode organizationNode) throws JsonProcessingException {
OrganizationalEntity organization = new OrganizationalEntity();
organization.setName(organizationNode.get("name").asText());

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions