jakartaee / jakartaee/jsonb-api
Convenience method for equating two JSON-B data objects
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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