feat(object-mapper): Honor the output class in ObjectMapperOutputProcessor on write operations#8420
Open
dylan-rumble wants to merge 1 commit into
Conversation
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.
Problem
When using the Symfony ObjectMapper integration (
stateOptions: new Options(entityClass: MyEntity::class)), the read side and write side are inconsistent in how they resolve the target class.On the read side,
ObjectMapperProvidercorrectly respects a configured output class, falling back to the operation class:On the write side,
ObjectMapperOutputProcessorignores theoutputclass entirely and always maps back to$operation->getClass():As a result, a write operation (
POST / PATCH / PUT) that declares a dedicatedoutputclass silently maps the persisted entity back to the resource class instead of the requested output DTO. There is no way to return a different representation from a write than from a read when using ObjectMapper.This is particularly limiting when the resource class itself cannot serve as a valid output representation for writes (for example, when the resource's IRI cannot be generated from the write result), forcing users to fall back to
output: falseand losing the response body altogether.Fix
Mirror the read side so the processor honors the operation's
outputclass when one is defined, falling back to the operation class otherwise:This makes read and write paths symmetric and lets a write operation return a dedicated output DTO via ObjectMapper.
Backward compatibility
Fully backward compatible: when no
outputclass is configured,getOutput()isnulland behavior is unchanged (maps to$operation->getClass()).