Boost Java Development Efficiency with Equator’s Automatic Object Comparison

This article walks through the pain points of manually logging Java object changes, introduces the open‑source Equator library, explains its field‑ and getter‑based comparison strategies, shows how to integrate it via Maven, and demonstrates clean change‑log output with flexible field filtering and deep‑structure support.

Ubiquitous Tech
Ubiquitous Tech
Ubiquitous Tech
Boost Java Development Efficiency with Equator’s Automatic Object Comparison

Programmer Xiao Li needs to record change logs for product information, capturing which fields changed, their old values, and new values. He first tries serializing the whole object to JSON and comparing the strings, which produces massive, noisy logs that include irrelevant fields like updateTime, overwhelming the operations team.

Realizing the manual approach is unsustainable as the number of fields grows, Xiao Li searches for a generic solution and discovers the open‑source library Equator , which can automatically compare object properties and ignore specified fields.

Equator is a Java utility that uses reflection to compare two objects' fields (or getter methods) and returns the set of differing properties. It solves common challenges:

Many fields, easy to miss: e.g., a User class with 30 fields would require cumbersome hand‑written equals() implementations.

Different object structures: comparing User and UserDTO where fields are not identical.

Ignoring irrelevant fields: such as createTime or updateTime in audit logs.

Deep comparison: handling collections and nested objects that equals() cannot compare effectively.

Equator addresses these issues with the following core features:

✅ Compare based on attributes or getter methods .

✅ Include or exclude specific fields for precise control.

✅ Support for complex objects and collection structures.

✅ Ready‑to‑use; no need to write custom equals() logic.

Two comparison strategies are provided: GetterBaseEquator – suitable for JavaBean‑compliant objects. FieldBaseEquator – compares fields directly, ignoring getters.

Integration steps:

Add the Maven dependency:

<dependency>
  <groupId>com.github.dadiyang</groupId>
  <artifactId>equator</artifactId>
  <version>1.0.4</version>
</dependency>

Define the domain classes, e.g.:

@Data
@AllArgsConstructor
public class User {
  private String name;
  private int age;
  private String email;
  private String address;
  // getters/setters omitted
}
@Data
@AllArgsConstructor
public class UserDTO {
  private String name;
  private int age;
  private String email;
  private String phoneNumber;
  // getters/setters omitted
}

Use Equator to compare objects, optionally ignoring fields like updateTime:

Equator equator = new Equator.Builder()
    .ignoreFields("updateTime")
    .build();
Map<String, Pair<Object, Object>> diff = equator.compare(user, userDTO);
// diff contains only the fields that actually changed

The article includes screenshots of the comparison results and a class diagram illustrating Equator’s internal structure.

Equator GitHub stars
Equator GitHub stars

By adopting Equator, developers can produce clean, concise change logs, reduce repetitive code, and improve overall development efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backendJavaReflectionMavenObject ComparisonEquator
Ubiquitous Tech
Written by

Ubiquitous Tech

A ubiquitous public account for pirate enthusiasts, regularly sharing curated experiences, tech learning, and growth insights. Currently publishing articles on AI RAG customer service, AI MCP technology, and open-source design. Personal free Knowledge Planet: Awakening New World Programmer.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.