Multiple GSON @SerializedName per field?

前端 未结 4 627
盖世英雄少女心
盖世英雄少女心 2020-12-07 19:26

Is there any way in Gson to map multiple JSON fields to a single Java object member variable?

Let\'s say I have a Java class...

public class MyClass          


        
4条回答
  •  长情又很酷
    2020-12-07 20:27

    In October 2015, Gson version 2.4 (changelog) added the ability to use alternate/multiple names for @SerializedName when deserializing. No more custom TypeAdapter needed!

    Usage:

    @SerializedName(value="name", alternate={"person", "user"})
    

    https://www.javadoc.io/doc/com.google.code.gson/gson/2.6.2/com/google/gson/annotations/SerializedName.html

提交回复
热议问题