Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[JsonEncoder] Replace normalizers by value transformers #59290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

mtarld
Copy link
Contributor

@mtarld mtarld commented Dec 23, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #59288
License MIT

For a better DX and to avoid confusion with Serializer's normalizers and denormalizers:

  1. Merge the NormalizerInterface and DenormalizerInterface to a single ValueTransformerInterface:
interface ValueTransformerInterface
{
    public function transform(mixed $value, array $options = []): mixed;

    public static function getJsonValueType(): Type;
}
  1. Replace the Normalizer and Denormalizer attributes by a single ValueTransformer attribute:
#[\Attribute(\Attribute::TARGET_PROPERTY)]
class ValueTransformer
{
    // ...

    public function __construct(
        callable|string|null $toNativeValue = null, // can be a callable or a ValueTransformerInterface service id
        callable|string|null $toJsonValue = null, // can be a callable or a ValueTransformerInterface service id
    ) {
        // ...
    }

    // ...

/cc @wouterj

@carsonbot carsonbot added this to the 7.3 milestone Dec 23, 2024
@mtarld mtarld force-pushed the feat/merge-normalizer branch from 3c5af0a to 0b105a9 Compare December 23, 2024 14:45
@mtarld mtarld changed the title [JsonEncoder] Replace normalizers by value resolvers [JsonEncoder] Replace normalizers by value transformers Dec 23, 2024
@mtarld mtarld force-pushed the feat/merge-normalizer branch from 0b105a9 to 877fba3 Compare December 23, 2024 14:46
@chalasr
Copy link
Member

chalasr commented Dec 23, 2024

Looks like psalm made a good point

@mtarld
Copy link
Contributor Author

mtarld commented Dec 23, 2024

Yep, I'm on it!

@mtarld mtarld force-pushed the feat/merge-normalizer branch 2 times, most recently from 93a0d7b to 0968e58 Compare December 23, 2024 15:00
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toPhp or toNative?
what's the requirements of the value returned by toJson (which is going to be a PHP value ;) )

@mtarld mtarld force-pushed the feat/merge-normalizer branch 2 times, most recently from 01c0880 to 906e354 Compare January 6, 2025 11:49
@mtarld mtarld force-pushed the feat/merge-normalizer branch 4 times, most recently from 7f848d9 to 2049277 Compare January 8, 2025 14:24
@OskarStark
Copy link
Contributor

If I get it right, the PR header needs an update, right?

@mtarld
Copy link
Contributor Author

mtarld commented Jan 9, 2025

Indeed, you're right, updated!

@nicolas-grekas
Copy link
Member

(rebase needed)

@mtarld mtarld force-pushed the feat/merge-normalizer branch from 2049277 to abe4ec9 Compare January 17, 2025 16:09
@mtarld mtarld force-pushed the feat/merge-normalizer branch 2 times, most recently from 507d527 to 2b64dcd Compare January 27, 2025 11:58
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one phpdoc thing and LGTM, thanks.

@mtarld mtarld force-pushed the feat/merge-normalizer branch from 2b64dcd to ced7191 Compare February 18, 2025 16:43
@chalasr
Copy link
Member

chalasr commented Feb 20, 2025

Thank you @mtarld.

@chalasr chalasr merged commit 68944f5 into symfony:7.3 Feb 20, 2025
9 of 11 checks passed
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DX][JsonEncoder] Can we find a better name for normalizer/encoder
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.