Skip to content

Fix ResourceSupport not serializable on spring boot 2.1.x - #2607

Open
ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:issue/1726
Open

ruthst00 wants to merge 2 commits into
spring-projects:mainfrom
ruthst00:issue/1726

Conversation

@ruthst00

Copy link
Copy Markdown

Fixes #1726

Root cause: DomainObjectReader.readPut() passes the raw ObjectNode (including _links) to mapper.readerFor(target.getClass()).readValue(...) for intermediate deserialization. Jackson sees _links, finds the inherited links field on RepresentationModel, and tries to set it — but it's unmodifiable.

Fix (5 files changed, 173 insertions):

  1. MappedJacksonProperties — Added isKnownJacksonProperty(String name) which returns true if a field is a mapped persistent property, an unmapped Jackson property (e.g. @Transient fields), or covered by @JsonAnySetter. Fields like _links that are unknown to Jackson return false.
  2. DomainObjectReader.readPut() — Added stripNonWritableFields() that deep-copies the ObjectNode and removes any fields not known to Jackson before the intermediate deserialization step.
  3. PersistentEntityResourceHandlerMethodArgumentResolver — Added the same stripping logic for the POST (create) path, plus a new PersistentEntities constructor parameter wired via RepositoryRestMvcConfiguration.
  4. RepositoryRestMvcConfiguration — Passes entities to the new constructor.
  5. DomainObjectReaderUnitTests — Added RepresentationModelEntity fixture and readPutWithLinksFieldDoesNotThrowForRepresentationModelSubclass test. All 43 tests pass.
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@ruthst00 ruthst00 changed the title Issue/1726 Fix ResourceSupport not serializable on spring boot 2.1.x Sep 13, 2026
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 13, 2026
Signed-off-by: ruthes00 <ruthes00@gmail.com>
…ation

Entities that extend RepresentationModel carry a private 'links' field
backed by an unmodifiable list. When a HAL client echoes back the
'_links' object in a PUT or POST body, Jackson attempts to set that
field via reflection and throws UnsupportedOperationException.

Fix: before handing the ObjectNode to Jackson for intermediate
deserialization (PUT path in DomainObjectReader.readPut) or for
direct deserialization (POST path in
PersistentEntityResourceHandlerMethodArgumentResolver), strip any
JSON fields that are not known to Jackson for the target type.

'Known to Jackson' means the field is either:
  - a mapped persistent property (fieldNameToProperty),
  - an unmapped Jackson property (e.g. @transient fields that
    Jackson can still deserialize), or
  - covered by a @JsonAnySetter catch-all.

A new MappedJacksonProperties.isKnownJacksonProperty(String) method
encapsulates this check. Fields like '_links' that are not in any of
these categories are removed from the ObjectNode before Jackson sees
it, preventing the UnsupportedOperationException.

Fixes: spring-projects#1726

Signed-off-by: Steve Rutherford <ruthes00@example.com>
Signed-off-by: ruthes00 <ruthes00@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RessourceSupport not serializable on spring boot 2.1.x [DATAREST-1363]

2 participants