Class CollectingProblemHandler

java.lang.Object
tools.jackson.databind.deser.DeserializationProblemHandler
tools.jackson.databind.deser.CollectingProblemHandler

public class CollectingProblemHandler extends DeserializationProblemHandler
Stateless DeserializationProblemHandler that collects recoverable problems into a per-call bucket stored in DeserializationContext attributes.

Design: This handler is completely stateless. The problem collection bucket is allocated per-call by ObjectReader.readValueCollectingProblems(...) and stored in per-call context attributes, ensuring thread-safety and call isolation.

Usage: This class is internal infrastructure, registered automatically by ObjectReader.problemCollectingReader(). Users should not instantiate or register this handler manually.

Design rationale - Context Attributes vs Handler State:

Problem collection state is stored in DeserializationContext attributes rather than within this handler for several reasons:

  1. Thread-safety: The handler instance is shared across all calls to the same ObjectReader. Storing mutable state in the handler would require synchronization and complicate the implementation.
  2. Call isolation: Each call to readValueCollectingProblems() needs its own problem bucket. Context attributes are perfect for this - they're created per-call and automatically cleaned up after deserialization.
  3. Immutability: Jackson's config objects (including handlers) are designed to be immutable and reusable. Storing per-call state violates this principle.
  4. Configuration vs State: The handler stores configuration (max problems limit) while attributes store runtime state (the actual problem list). This separation follows Jackson's design patterns.

The handler itself is stateless - it's just a strategy for handling problems. The actual collection happens in a bucket passed through context attributes.

Recoverable errors handled:

Default values: Primitives receive zero/false defaults; reference types (including boxed primitives) receive null to avoid masking nullability issues.

DoS protection: Collection stops when the configured limit (default 100) is reached, preventing memory/CPU exhaustion attacks.

JSON Pointer: Paths are built from parser context following RFC 6901, with proper escaping of ~ and / characters via jackson-core's JsonPointer class.

Since:
3.1