Skip to content
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

Replace usages of org.json with Jackson #2520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nscuro
Copy link
Member

@nscuro nscuro commented Feb 23, 2023

Description

In cases where we don't directly map JSON to and from POJOs, we currently predominantly use org.json:json.

That library once shipped with Unirest, but Unirest switched to another serialization library, and we have moved away from Unirest recently, too.

This PR replaces usages of org.json with Jackson.

Addressed Issue

Closes #1113

Additional Details

Another option would've been to use JSON-P, but the spec and its implementations lack capabilities of object mapping. That is, it's not possible to put a POJO into a JSON object using the JSON-P API. Jackson supports this.

A new utility class, org.dependencytrack.common.Json, has been added which includes various methods (e.g. optString, optArray etc.) that behave just like their counterparts in org.json. This was done to reduce the amount of necessary refactoring to a minimum.

Tests for various existing JSON transformations (e.g. the FPF) have been added along the way, to ensure that this change does not introduce regressions.

Usage of the org.json.* package has been blacklisted with Checkstyle.

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@walterdeboer
Copy link

walterdeboer commented Mar 9, 2023

@nscuro Let's get this out of the way :-) nscuro#187

@nscuro
Copy link
Member Author

nscuro commented Mar 9, 2023

Thanks @walterdeboer! I did put this on hold because there are (were?) still pending PRs that utilize org.json, and I wanted to avoid forcing contributors to rebase their PRs 😅

Greatly appreciate the work, that'll certainly speed things up!

@walterdeboer
Copy link

I'm one of the pending PR's, that's why I wanted to give it a push :-)

@sonatype-lift
Copy link
Contributor

sonatype-lift bot commented Mar 10, 2023

🛠 Lift Auto-fix

Some of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1

# Download the patch
curl https://lift.sonatype.com/api/patch/github.com/DependencyTrack/dependency-track/2520.diff -o lift-autofixes.diff

# Apply the patch with git
git apply lift-autofixes.diff

# Review the changes
git diff

Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command:

curl https://lift.sonatype.com/api/patch/github.com/DependencyTrack/dependency-track/2520.diff | git apply

Once you're satisfied, commit and push your changes in your project.

Footnotes

  1. You can preview the patch by opening the patch URL in the browser.

@walterdeboer
Copy link

walterdeboer commented Mar 10, 2023

@nscuro And some sonatype-lift fixes here: nscuro#188 (rebased)

@nscuro nscuro marked this pull request as ready for review March 26, 2023 21:00
@nscuro nscuro added this to the 4.9 milestone Apr 4, 2023
Co-authored-by: Walter de Boer <walterdeboer@dbso.nl>
Signed-off-by: nscuro <nscuro@protonmail.com>
@@ -93,21 +94,21 @@ public void testParseSeveritiesNvd() throws IOException {

// By default NVD is first priority for CVSS, no need to set config property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nscuro curious question. Lately i've seen NVD "being re-evaluated" or not evaluated at all. Ive noticed some wonkiness with some tools (not sure i've seen it in DT), where it doesn't seem to like that status. Do we defer to another alias (if they are on) for the scoring if NVD has not evaluated it??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you asking in general, or specific for Snyk?

Generally we do not re-use scoring of aliasing vulnerabilities, if a given vuln does not have a scoring.

For Snyk specifically, they provide at least one score for each vulnerability. Beside Snyk's own scoring, and the "offical" NVD one, there is also vendor-specific scoring from Red Hat, SUSE, etc.; In that case DT should follow a priority list of sorts, where it would fall back to the next preferred source if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thats what i was thinking. following a sequence of logic if there happens to be a vuln that does not have a score (for some reason) to default to the next best source.

@nscuro nscuro modified the milestones: 4.9, 4.10 Jul 6, 2023
@nscuro
Copy link
Member Author

nscuro commented Jul 6, 2023

Moved to 4.10 as we want this to be thoroughly exercised in users' test environments. Merging shortly before 4.9 release is too risky.

@melba-lopez melba-lopez added enhancement New feature or request on hold labels Jul 28, 2023
@nscuro nscuro removed this from the 4.10 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request on hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove reliance on org.json.JSON
3 participants