Skip to content
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

@SerializedName within deserialization broken? #1321

Open
MrToon69 opened this issue May 19, 2021 · 6 comments
Open

@SerializedName within deserialization broken? #1321

MrToon69 opened this issue May 19, 2021 · 6 comments

Comments

@MrToon69
Copy link

Q A
Bug report? yes?
Feature request? no
BC Break report? no
RFC? yes

When I am using the annotation @SerializedName as described within the documentation, including SerializedNameAnnotationStrategy.

I expect that with serialization the property name is being converted to that what is stated within @SerializedName.
That seems to work as intended.
But when I use deserialization (json > object), @SerializedName is also being used to populate the property instead of the property name.

Compared to other serializers, like that of the Symfony component. Sort like annotations of @SerializedName is exclusively used for serialization only, not for deserialization.

Is this by design? And what would be the recommended method within FOS to deserialize towards object properties and only use @SerializedName within serialization?

@goetas
Copy link
Collaborator

goetas commented May 21, 2021

I'm not sure if I understand correctly, are you saying that you want @SerializedName only for serialization and not deserialization?

@MrToon69
Copy link
Author

Correct.

This seem to be the behaviour in other serializer projects, like the mentioned example https://symfony.com/doc/current/components/serializer.html

Is there a other method to segregate deserialize / serialize within your tool without customization?

@andrei-dascalu
Copy link
Contributor

Out of curiosity, wouldn't that mean that you wouldn't be able to deserialize the same json into the structure from which you created it? If you had

/**
* @JMS/SerializedName("whatever")
* /
private string $testVar;

you'd serialize into { "whatever": "" } but you'd need to deserialize into something the variable is private string $whatever;

Right?

@goetas
Copy link
Collaborator

goetas commented Jul 4, 2021

@andrei-dascalu i'm not sure that this is a valid bug report, did anyone manage to reproduce such issue?

@andrei-dascalu
Copy link
Contributor

@goetas it's not a bug report, just thinking out loud on what would happen if serialization/deserialization would be segregated by default.

@goetas
Copy link
Collaborator

goetas commented Aug 23, 2021

@andrei-dascalu understood.

/**
* @JMS/SerializedName("whatever")
* /
private string $testVar;

both serialization and deseralization should wotk/produce this json: { "whatever": "abc" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants