Partial serialization

Open
#838 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java

Research direction

Start by tracing ObjectMapper creation and custom serializer registration in AbstractBomGenerator, its implementations, and the Parser implementations. Review how serialization and deserialization are currently configured per Version, then define the public accessor and caching behavior. Done means partial BOM objects can use the same configured mapper and repeated document loops do not create redundant ObjectMapper instances.

Written by the indexing model from the issue text.

Description

Currently the AbstractBomGenerator and it's implementations use several custom serializers, which are registered in an always new ObjectMapper.

Handling partial serialization of a BOM is not cleanly possible (e.g. serializing a single vulnerability or a list of components), since the ObjectMapper is not exposed and the AbstractBomGenerator signatures do not match. The only way of achieving this, while serializing exactly as this reference implementation is either using reflection hacks or by full on copy pasting the code.

Additionally, the Jackson ObjectMapper isn't a lightweight object. For a simple parse-modify-writeback loop of a cyclonedx document two separate ObjectMappers are created on every such loop, which is fully unnecessary.

Feature request / proposal:

  • Decouple ObjectMapper creation and configuration from AbstractBomGenerator and Parser implementations
  • Expose the ObjectMapper in a public accessor
  • While at it, memorize/cache the ObjectMapper instance per Version, so that a single instance of an ObjectMapper is used for serialization and deserialization

Benefits of the change:

  • enables partial serialization of BOMs and cleanly working directly with document parts.
  • reduces / stabilizes memory footprint when (de-)serializing multiple documents
  • improves performance when (de-)serializing from the second document onward (when the ObjectMapper has been created)

Context of this request:
I'm currently working on a private project (private for now, currently too raw / alpha) which stores and queries CycloneDX. I'm heavily using Postgres JSONB support, and being able to properly work with partial objects is a requirement for me.

Is there interest in a feature like that? I'll build that for myself anyway, but having it integrated in the core lib would be cleaner for me, and might benefit a few other people, so I gladly can make a PR.
Just wanted to ask before dropping a rather big change out of the blue.

Dominant language
Java
Stars
124
Forks
97
Avg merge
2d 14h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CycloneDX/cyclonedx-core-java

All issues in CycloneDX/cyclonedx-core-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.