Gson: SerializedName should allow multiple names to be matched to a single name for input

Created on 21 Apr 2015  ยท  17Comments  ยท  Source: google/gson

Most helpful comment

For Kotlin @SerializedName(value="firstName", alternate= ["userName"])

All 17 comments

+1

@inder123 @ikkyu0319 Do you mean something like this (this isn't available yet) ?

@SerializedName({"name", "firstName", "userName"})
public String name;

@SerializedName("id")
public String id;

where the idea is to re-use a model for multiple API endpoints but the attribute returned has a different name?

Yes~ I need this~~ @JakeWharton @inder123 @fahimk

To maintain backward compatibility, I revised it to:

@SerializedName(value="default_name", alternate={"name", "firstName", "userName"})
public String name;

Let me know if you see a problem with this.

This shipped in 2.4

@inder123 this is great, thanks for working on it.

@fahimk great. Looking forward to learning how it worked for you.

How can i use this in kotlin ?
@SerializedName(value="name", alternate={"person", "user"})
this gives me unexpected token error

Use arrayOf

On Mon, Aug 7, 2017 at 11:55 PM GaniduAsh notifications@github.com wrote:

How can i use this in kotlin ?
@serializedname(value="name", alternate={"person", "user"})
this gives me unexpected token error

โ€”
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-320867508, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEWhHbwfZtXFbc8zp8jr8iunW36zOks5sWAZzgaJpZM4EFYUt
.

yes found it thanks

Can we let the alternative or on of the alternatives get chosen when serializing object that will be sent to server ?

For Kotlin @SerializedName(value="firstName", alternate= ["userName"])

I am trying this, but it's not working.
@SerializedName(value = "text", alternate = {"text", "image", "document", "voice", "audio", "video", "location", "contacts"})
private String content;

@inder123, any suggestion ?

@sunil965 alternate should be an array not object.

What up? May i help u.?

On Fri, 21 Aug 2020, 12:43 am Akinsete Sunday, notifications@github.com
wrote:

@sunil965 https://github.com/sunil965 alternate should be an array not
object.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-677819572, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AJJORC54DRGF7YDFHGJK7OLSBVRS3ANCNFSM4BAVQUWQ
.

Hi Google/Gson,

I don't know why I am getting this message, can you please confirm.

On Thu, 20 Aug, 2020, 11:45 PM AungHtetKyawWho, notifications@github.com
wrote:

What up? May i help u.?

On Fri, 21 Aug 2020, 12:43 am Akinsete Sunday, notifications@github.com
wrote:

@sunil965 https://github.com/sunil965 alternate should be an array not
object.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-677819572, or
unsubscribe
<
https://github.com/notifications/unsubscribe-auth/AJJORC54DRGF7YDFHGJK7OLSBVRS3ANCNFSM4BAVQUWQ

.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-677820577, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AGL6N5Z5DJMJVBWEEMY7LQLSBVR3FANCNFSM4BAVQUWQ
.

๐Ÿ™๐Ÿ™

On Sun, 23 Aug 2020, 7:47 am Sunil Kumar, notifications@github.com wrote:

Hi Google/Gson,

I don't know why I am getting this message, can you please confirm.

On Thu, 20 Aug, 2020, 11:45 PM AungHtetKyawWho, notifications@github.com
wrote:

What up? May i help u.?

On Fri, 21 Aug 2020, 12:43 am Akinsete Sunday, <[email protected]

wrote:

@sunil965 https://github.com/sunil965 alternate should be an array
not
object.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-677819572, or
unsubscribe
<

https://github.com/notifications/unsubscribe-auth/AJJORC54DRGF7YDFHGJK7OLSBVRS3ANCNFSM4BAVQUWQ
>

.

โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-677820577, or
unsubscribe
<
https://github.com/notifications/unsubscribe-auth/AGL6N5Z5DJMJVBWEEMY7LQLSBVR3FANCNFSM4BAVQUWQ

.

โ€”
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/639#issuecomment-678716487, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AJJORCZ5ODZBKWAO36CAOZLSCBU4DANCNFSM4BAVQUWQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GoogleCodeExporter picture GoogleCodeExporter  ยท  15Comments

cayhorstmann picture cayhorstmann  ยท  13Comments

GoogleCodeExporter picture GoogleCodeExporter  ยท  14Comments

GoogleCodeExporter picture GoogleCodeExporter  ยท  15Comments

LucianWang picture LucianWang  ยท  42Comments