Skip to content

Add support for serializing Double values in objectToJsonNode #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
robin38n opened this issue May 20, 2025 · 3 comments · Fixed by #26
Closed

Add support for serializing Double values in objectToJsonNode #25

robin38n opened this issue May 20, 2025 · 3 comments · Fixed by #26
Labels
enhancement New feature or request

Comments

@robin38n
Copy link

Background
I’m integrating the SPDX JSON-LD serializer into my SBOM generation pipeline, and I need to include CVSS v3 scores (type Double) on my CvssV3VulnAssessmentRelationship objects. The builder exposes a setScore(Double) method, but when the serializer encounters a Double it doesn’t know how to turn it into a JSON node, and throws an InvalidSPDXAnalysisException.

Current Behavior

  • objectToJsonNode(...) handles String, Integer, Boolean, etc., but has no branch for Double.
  • Any Double-typed field causes an exception.

Expected Behavior

  • When an Object is a Double, it should be serialized as a DoubleNode.

Proposed Change

 // … existing imports …
+import com.fasterxml.jackson.databind.node.DoubleNode;
 
 private JsonNode objectToJsonNode(Object object, …) {
     // … earlier branches …
     } else if (object instanceof Integer) {
         return new IntNode((Integer)object);
+    } else if (object instanceof Double) {
+        return new DoubleNode((Double)object);
     } else if (object instanceof IndividualUriValue) {
         …
     }
 }
@bact
Copy link
Collaborator

bact commented May 20, 2025

As score is xsd:decimal, we may need DecimalNode instead?

@goneall
Copy link
Member

goneall commented May 21, 2025

As score is xsd:decimal, we may need DecimalNode instead?

Currently, decimals are translated to double type, so we lose the information on the decimal type.

I personally think this loss of fidelity is ok, but if we want to retain the decimal type, we need to update the code in the model to Java library.

@goneall
Copy link
Member

goneall commented May 23, 2025

Since Java doesn't support a primitive decimal type, it would be difficult to retain the fidelity. I'll create a pull request to support Double.

goneall added a commit that referenced this issue May 23, 2025
Fixes #25

Also updates the minimum Java levels in the POM file since the library
already requires version 11 or higher
goneall added a commit that referenced this issue Jun 6, 2025
Fixes #25

Also updates the minimum Java levels in the POM file since the library
already requires version 11 or higher
@bact bact added the enhancement New feature or request label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants