Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4f94e17
Implement error collection for deserialization (#1196)
sri-adarsh-kumar Oct 24, 2025
290d944
Apply GPT-5 review fixes for issue #1196
sri-adarsh-kumar Oct 24, 2025
875c953
Refactor CollectingErrorsTest based on review feedback
sri-adarsh-kumar Oct 25, 2025
6914713
Add documentation for error collection feature (#1196)
sri-adarsh-kumar Oct 25, 2025
b6ba90b
Refactor CollectingErrorsTest: remove deprecated APIs and clean up ex…
sri-adarsh-kumar Oct 25, 2025
24604ba
Restore accidentally deleted module-info.java
sri-adarsh-kumar Oct 25, 2025
f0c4342
Address PR #5364 review feedback: rename API and improve documentation
sri-adarsh-kumar Oct 26, 2025
9e799af
Merge branch '3.x' into issue-1196-error-collection-attempt-1
sri-adarsh-kumar Nov 3, 2025
dd562e9
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 6, 2025
752ca5f
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 18, 2025
9ae5948
Minor streamlining
cowtowncoder Nov 18, 2025
f95ebb9
Merge branch 'issue-1196-error-collection-attempt-1' of github.com:sr…
cowtowncoder Nov 18, 2025
42446d2
PR #5364 refinements: move max-problem config to handler, refactor co…
sri-adarsh-kumar Nov 18, 2025
9b874ad
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 19, 2025
43ae2fb
Merge branch 'issue-1196-error-collection-attempt-1' of github-zse:sr…
sri-adarsh-kumar Nov 19, 2025
8fa8429
issue-1196: Fix exception handling when problem collection limit reached
sri-adarsh-kumar Nov 19, 2025
fa3fbe3
Merge branch '3.x' into issue-1196-error-collection-attempt-1
sri-adarsh-kumar Nov 19, 2025
d5e1d23
issue-1196: Fix README documentation inaccuracy
sri-adarsh-kumar Nov 19, 2025
7782931
issue-1196: Refactor problem-collecting deserialization for _bind/_bi…
sri-adarsh-kumar Nov 20, 2025
429c90a
Merge branch '3.x' into issue-1196-error-collection-attempt-1
sri-adarsh-kumar Nov 20, 2025
597f515
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 20, 2025
ee24975
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 23, 2025
fbb9dc8
Minor tweaks, comment adds
cowtowncoder Nov 23, 2025
8d0bdc5
Merge branch '3.x' into issue-1196-error-collection-attempt-1
cowtowncoder Nov 25, 2025
9adc377
Add an overload to allow passing custom `CollectingProblemHandler`
cowtowncoder Nov 25, 2025
96cc46d
Add missing overload, fix "match multiple" argument
cowtowncoder Nov 25, 2025
2708745
Javadoc improvement
cowtowncoder Nov 25, 2025
c040152
One final thing: add CREDITS
cowtowncoder Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,60 @@ This will deserialize JSON fields with `known_as`, as well as `identifer` and `f
Note: to use the `@JsonAlias` annotation, a `@JsonProperty` annotation must also be used.

Overall, Jackson library is very powerful in deserializing objects using builder pattern.


## Tutorial: Collecting multiple errors (3.1+)

One recently introduced feature is the ability to collect multiple deserialization errors instead of failing fast on the first one. This can be really handy for validation use cases.

By default, if Jackson encounters a problem during deserialization -- say, string `"xyz"` for an `int` property -- it will immediately throw an exception and stop. But sometimes you want to see ALL the problems in one go.

Consider a case where you have a couple of fields with bad data:

```java
class Order {
public int orderId;
public Date orderDate;
public double amount;
}

String json = "{\"orderId\":\"not-a-number\",\"orderDate\":\"bad-date\",\"amount\":\"xyz\"}";
```

Normally you'd get an error about `orderId`, fix it, resubmit, then get error about `orderDate`, and so on. Not fun. So let's collect them all:

```java
ObjectMapper mapper = new JsonMapper();
ObjectReader reader = mapper.readerFor(Order.class).problemCollectingReader();

try {
Order result = reader.readValueCollectingProblems(json);
// worked fine
} catch (DeferredBindingException ex) {
System.out.println("Found " + ex.getProblems().size() + " problems:");
for (CollectedProblem problem : ex.getProblems()) {
System.out.println(problem.getPath() + ": " + problem.getMessage());
// Can also access problem.getRawValue() to see what the bad input was
}
}
```

This will report all 3 problems at once. Much better.

By default, Jackson will collect up to 100 problems before giving up (to prevent DoS-style attacks with huge bad payloads). You can configure this:

```java
ObjectReader reader = mapper.readerFor(Order.class).problemCollectingReader(10); // limit to 10
```

Few things to keep in mind:

1. This is best-effort: not all problems can be collected. Malformed JSON (like missing closing brace) or other structural problems will still fail immediately. But type conversion errors, unknown properties (if you enable that check), and such will be collected.
2. Error paths use JSON Pointer notation (RFC 6901): so `"/items/0/price"` means first item in `items` array, `price` field. Special characters get escaped (`~` becomes `~0`, `/` becomes `~1`).
3. Each call to `readValueCollectingProblems()` gets its own problem bucket, so it's thread-safe to reuse the same `ObjectReader`.
4. Fields that fail to deserialize get default values (0 for primitives, null for objects) during the attempt, but if any problems are collected, only the problems are reported in the `DeferredBindingException` - the partial result is not returned.

This is particularly useful for things like REST API validation (return all validation errors to client), or batch processing (log errors but keep going), or development tooling.

# Contribute!

We would love to get your contribution, whether it's in form of bug reports, Requests for Enhancement (RFE), documentation, or code patches.
Expand Down
10 changes: 10 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ Fouad Almalki (@Eng-Fouad)
with Jackson 3
[3.0.3]

Oliver Drotbohm (@odrotbohm)
* Requested #1196: Add opt-in error collection for deserialization
[3.1.0]

@sri-adarsh-kumar
* Contributed #1196: Add opt-in error collection for deserialization
[3.1.0]

Hélios Gilles (@RoiSoleil)
* Contributed #5413: Add/support forward reference resolution for array values
[3.1.0]


3 changes: 3 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Versions: 3.x (for earlier see VERSION-2.x)

3.1.0 (not yet released)

#1196: Add opt-in error collection for deserialization
(requested by @odrotbohm)
(contributed by @sri-adarsh-kumar)
#5350: Add `DeserializationFeature.USE_NULL_FOR_MISSING_REFERENCE_VALUES` for
selecting `null` vs "empty/absent" value when deserializing missing `Optional` value
#5361: Fix Maven SBOM publishing (worked in 3.0.0-rc4 but not in rc5 or later)
Expand Down
Loading