Added new Associations.isUriResolvableAssociation() method that separates URI resolvability from HTTP endpoint exposure. - #2601
Open
ruthst00 wants to merge 3 commits into
Conversation
…rategy Closes spring-projectsGH-1515 When the ANNOTATED repository detection strategy is active, repositories that are not annotated with @RepositoryRestResource have isExported() == false. Previously, the AssociationUriResolvingDeserializerModifier in both PersistentEntityJacksonModule and PersistentEntityJackson2Module used Associations.isLinkableAssociation() to decide whether to register a UriStringDeserializer for an association property. That method checks metadata.isExported() for the target type, which returns false under the ANNOTATED strategy for un-annotated repositories. As a result, the UriStringDeserializer was never registered, and Jackson fell back to its default deserializer, which cannot construct an entity from a plain URI string — causing a JsonMappingException (400 Bad Request). The fix introduces a new Associations.isUriResolvableAssociation() method that separates URI resolvability from HTTP endpoint exposure: - It returns true whenever a ResourceMetadata (i.e. a repository) exists for the target type, regardless of whether that repository is exported as an HTTP endpoint. - The owner-level check is relaxed: instead of delegating to ResourceMetadata.isExported(property) — which internally checks the target type's export status — it only checks whether the property has been explicitly suppressed via @RestResource(exported = false). Both PersistentEntityJacksonModule and PersistentEntityJackson2Module are updated to use isUriResolvableAssociation() in their deserializer modifier, while isLinkableAssociation() continues to be used for serialization (link rendering), where the HTTP export status check is still correct and intentional. New test coverage: - AssociationsUnitTests: 4 new unit tests for isUriResolvableAssociation covering the exported, unexported, no-repository, and null-argument cases. - AnnotatedStrategyUriDeserializationIntegrationTests: full JPA integration test with Member/@manytoone Profile scenario, verifying that: (1) POST /members with a profile URI succeeds (201 Created), (2) GET /profiles returns 404 (un-annotated repo not exposed), and (3) GET /members returns 200 (annotated repo is exposed). Signed-off-by: ruthes00 <ruthes00@gmail.com>
The AssociationUriResolvingDeserializerModifier was changed to call isUriResolvableAssociation() exclusively, but existing unit tests only stub isLinkableAssociation() on the mock Associations bean. This caused 4 tests in PersistentEntityJackson2ModuleUnitTests to fail because the mock returned false (default) for isUriResolvableAssociation(). Fix: use isUriResolvableAssociation() || isLinkableAssociation() so that both the new ANNOTATED-strategy scenario and the existing test stubs work correctly. The UriStringDeserializer is registered whenever either method returns true. Signed-off-by: ruthes00 <ruthes00@gmail.com>
Signed-off-by: ruthes00 <ruthes00@gmail.com>
ruthst00
force-pushed
the
DATAREST-1195-ruthes00
branch
from
September 10, 2026 18:59
3cee5f7 to
64b6a0e
Compare
Associations.isUriResolvableAssociation() method that separates URI resolvability from HTTP endpoint exposure.Associations.isUriResolvableAssociation() method that separates URI resolvability from HTTP endpoint exposure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1515
Root Cause: When the
ANNOTATEDrepository detection strategy is active, repositories without@RepositoryRestResourcehaveisExported() == false. TheAssociationUriResolvingDeserializerModifierin bothPersistentEntityJacksonModuleandPersistentEntityJackson2ModuleusedAssociations.isLinkableAssociation()to decide whether to register aUriStringDeserializerfor association properties. That method checksmetadata.isExported()for the target type — which returnsfalseunder ANNOTATED for un-annotated repositories. The deeper issue was thatPersistentPropertyResourceMapping.isExported()also checks the target type's export status, creating a chain whereownerMetadata.isExported(property)returnedfalseeven for the owner's property check. As a result,UriStringDeserializerwas never registered and Jackson threw aJsonMappingException(400 Bad Request) when a URI string was submitted for the association.Fix: A new
Associations.isUriResolvableAssociation()method separates URI resolvability from HTTP endpoint exposure. It returnstruewhenever aResourceMetadata(i.e. a repository) exists for the target type, regardless of export status. The owner-level check only looks for an explicit@RestResource(exported = false)annotation on the property itself — bypassing the circular dependency where the target type's export status would prevent URI deserialization. Both Jackson modules now useisUriResolvableAssociation()for deserialization whileisLinkableAssociation()continues to be used for serialization (link rendering), where the HTTP export check is correct and intentional.Test coverage added (9 files, 586 lines):
AssociationsUnitTests: 4 new unit tests forisUriResolvableAssociation(all 14 tests pass)AnnotatedStrategyUriDeserializationIntegrationTests: Full JPA integration test withMember/@ManyToOne Profilescenario — all 3 tests pass: POST succeeds (201),/profilesreturns 404 (not exposed),/membersreturns 200 (exposed)