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

Alias support And api to retrieve type info #519

Closed
shxhzhxx opened this issue Jul 18, 2019 · 3 comments
Closed

Alias support And api to retrieve type info #519

shxhzhxx opened this issue Jul 18, 2019 · 3 comments
Labels

Comments

@shxhzhxx
Copy link

I know that SerialName could overriding property name.
But what I need is Many-to-one mapping.
eg.
data class Example( @JsonAlias("tips", "errorMsg", "message") val msg: String )
"tips,errorMsg,message,msg" any of these appears in raw json data would be the value of msg property,
although the priority is arbitrary.

To work around type erasure, type info is necessary. If I can retrieve it from KSerializer,
could eliminate the need to add additional parameter.

@pdvrieze
Copy link
Contributor

Perhaps this feature should be supported in the general case, not only for Json. It is not too hard to implement as the structure containing the field has access to the child descriptors and can search for one with the given alias. The hardest would be for the plugin to check against duplicates.

@sandwwraith
Copy link
Member

  1. Duplicate of Can SerialName annotation support alternate? #203
  2. Type info can be obtained from typeOf function. Serialization-related metadata is available in KSerializer.descriptor.

@sschuberth
Copy link
Contributor

I know that SerialName could overriding property name.
But what I need is Many-to-one mapping.

For people coming across here: Use @JsonName instead of @SerialName.

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

No branches or pull requests

4 participants