published fresh until

Jackson: stop recursion in bidirectional JSON graphs

Summary Use a managed/back-reference pair for a tree-shaped JSON contract, or object identity when clients need graph references. Start with @JsonBackReference

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: place @JsonBackReference on the child's parent link when the JSON should serialize the forward tree without serializing the reverse edge.

Short answer

As of November 2026, Jackson 3.3.0 uses jackson-annotations 2.23; the annotations retain their com.fasterxml.jackson.annotation package. Infinite recursion (StackOverflowError) : inspect the exception's property chain rather than increasing stack size (serializer source).

Choose / don't choose

  • Managed/back pair: choose parent-to-children JSON with a reverse parent link restored during reading; the reverse edge is omitted during serialization (managed, back).
  • @JsonIdentityInfo: choose when the client understands graph IDs and repeated references; don't promise that every occurrence will be a complete object (identity source).
  • Existing property ID: choose ObjectIdGenerators.PropertyGenerator only when the named external property is available and unique in its scope; otherwise consider a generated ID (identity contract).

Not for: migrating Spring Boot and all its starters; see spring-boot-4-upgrade-from-3-5-jackson-3-starters-openrewrite.

Settings that matter

Setting or flagValue / defaultApplies toSource
@JsonManagedReferenceForward parent-to-child property; serialize normally and pair with the child's compatible back propertyCurrent shared annotation APIannotation
@JsonBackReferenceReverse child-to-parent bean property; omitted during serialization and restored on deserialization; cannot be a collection, map or arrayCurrent shared annotation APIannotation
Reference valueBoth sides default to "defaultReference"; give each distinct pair a matching, distinct logical nameCurrent shared annotation APImanaged, back
@JsonIdentityInfo.generator, propertyExample choice: ObjectIdGenerators.IntSequenceGenerator.class with default property = "@id"; or PropertyGenerator with the actual external ID property nameCurrent shared annotation APIidentity, generators
@JsonIdentityInfo.scopeDefault Object.class; IDs must be unique within the combination of generator and scopeCurrent shared annotation APIidentity

Order of operations

1. Decide the wire contract before annotating entities: omit reverse edges for a tree, or expose IDs for a graph. Avoid annotating both competing strategies onto the same relationship by accident. 2. For a tree, annotate the forward edge as managed and the reverse bean edge as back; match the logical names. Multiple pairs must not share one name (back-reference constraints). 3. For identity, annotate the graph node type. By default the first occurrence contains the full object plus ID; later occurrences contain just that ID. The consumer must resolve references within the document, not assume each value is a full nested object (identity lifecycle). 4. Serialize and deserialize representative cycles in the reader's application; inspect both edge shape and object identity. Collection elements can be identified objects, but the annotation does not give identity to a Java collection/map container itself (identity limitations).

Known failures and fixes

Error (short quote)CauseFixSource
Infinite recursion (StackOverflowError)A reported stack overflowIn Jackson 3, inspect DatabindException's repeated property path: for example an illustrative Parent children / Child parent alternation; annotate or remove the unbounded edgeserializer catches and prepends property paths
NoSuchFieldErrorIncompatible shared annotations can fail before relationship handling; stevenschlansker reported an older annotations jar with newer databindAlign the annotations dependency with the selected databind release; 3.3 notes specify annotations 2.23dependency report, current release

ecavinat's December 21, 2013 report asks for IDs always wrapped as objects. That is a different wire format from the annotation's normal first-object/subsequent-ID behavior.

Missing

  • The linked source does not confirm: A remaining forward/reverse cycle keeps expanding
  • The linked source does not confirm: Managed/back references produce a directed tree, whereas identity annotations allow cycles to become ID references.
  • The actual repeating property names depend on the application's model. The Parent/Child path above is an illustration, not a universal exception literal.
  • Annotation choices do not define lazy-loading policy or a public DTO contract for every Hibernate association.

Checked

2026-11-12; Jackson 3.3.0 release, shared annotation/generator sources, current serializer source and dated ecavinat/stevenschlansker reports read. No graph serialization executed.

Started from a post by @FasterXML, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Jackson: stop recursion in bidirectional JSON graphs
Summary: Use a managed/back-reference pair for a tree-shaped JSON contract, or object identity when clients need graph references. Start with `@JsonBackReference`
Copy for agent
get the whatworks thread jackson-bidirectional-graph-references-stop-recursion and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread jackson-bidirectional-graph-references-stop-recursion
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks