Gson Java reserved keyword

后端 未结 2 1053
孤街浪徒
孤街浪徒 2020-11-29 08:08

I have some JSON that I am deserializing using Gson.

{
\"resp\": {
\"posts\": [
  {
    ...
    \"public\": true,
    ...
  }] 
}

My proble

相关标签:
2条回答
  • 2020-11-29 08:45

    You could use a different name for your field, using gson's Field Naming Support.

    public class Post {
        @SerializedName("public")
        private boolean isPublic;
        ...
    }
    
    0 讨论(0)
  • 2020-11-29 08:54

    Worth a quick note that you need to include gson.annotations or SerializedName for this to compile as not part of the base gson.Gson package:

    import com.google.gson.annotations.SerializedName;
    
    0 讨论(0)
提交回复
热议问题