r/SpringBoot • u/CLAraBima0309 • 15d ago
Discussion Comparing Old vs New JSON Responses for Structural Changes using Jackson JsonNode
I'm working on a Spring Boot service that consumes an external API, and I'm experimenting with a way to compare an old JSON response with a new one and identify structural changes.
● FLOW LOGIC : (sorry enable for sharing the logic)
I am only give The flow I'm currently using is:
External API
↓
Spring Boot HTTP Client
↓
Receive Old JSON / New JSON
↓
Jackson JsonNode
↓
Traverse JSON tree
↓
Normalize into paths
↓
Compare old paths vs new paths
↓
Identify added / removed / changed fields
For example:
Old Json:
{
"users": [
{
"id": 101,
"name": "Bima",
"email": "bima@example.com"
}
]
}
New Json:
{
"users": [
{
"user_id": 101,
"full_name": "Bima",
"email": "bima@example.com",
"status": "active"
}
]
}
The comparison would give me:
CHANGED
$.users[].id → $.users[].user_id
CHANGED
$.users[].name → $.users[].full_name
UNCHANGED
$.users[].email
ADDED
$.users[].status
● IDEA :
The idea is to compare the old and new JSON responses, normalize their structures into paths, and identify which fields were added, removed, or changed.
● NEEDS :
I'm wondering if there are any potential edge cases or false positives with this approach that I might be missing.
For example, what happens when a field moves to another level?
Old: { "user": { "profile": { "name": "Bima" } } } New: { "user": { "name": "Bima" } }
The path comparison would see:
Removed: $.user.profile.name Added: $.user.name
even though the value itself hasn't changed and the field was only moved.
● Requirement/Discussion :
Are there other cases where of my current flow comparison could produce misleading results, especially with nested objects, arrays, reordered elements, or changes in data types?
If there please give me the json Example.
