jakartaee / jakartaee/jsonb-api

Convenience method for equating two JSON-B data objects

Open
#148 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
95
Forks
41
Avg merge
1d 6h
Merged PRs (30d)
35

Description

It is commonly necessary to test if two Java objects representing JSON data are equal to one another. For example, consider the following class:
```java
public class MyData {
public String prop1;
public int prop2;
public String prop3;
@JsonbIgnore
public String ignoreThis;
private Set extraData;
}
```

The current solutions for doing this are:
1. Override Object.equals() (tedious if you have lots of properties)
1. Use Lombok annotations. Not everyone wants to use Lombok. Additionally it does not honor JSON-B overrides such as visibility strategy to make private fields accessible, or `@JsonbIgnore` to make public fields hidden
1. Use `@JsonbPropertyOrder` to force property ordering, call `jsonb.toString(pojo)` and then compare objects as strings. This is brittle and has performance drawbacks

It would be nice if there was a convenience method that would automatically compare the quality of two JSON-B objects by only comparing equality of their JSON-B properties. For example:
```java
MyData a = // ...
MyData b = // ...

// verifies that the properties: prop1, prop2, and prop3 are equal
assertTrue(Jsonb.equals(a, b));
```

Contributor guide

Open the contributing guide

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.

Research direction

Start with the proposed Jsonb.equals(a, b) entry point and review the JSON-B property rules described in the issue, including @JsonbIgnore, visibility, and property ordering. Done means an agreed API design and implementation that compares JSON-B properties without relying on string ordering, with tests covering the shown MyData case and ignored properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.