pojo parse gson with invalid java names

后端 未结 3 965
滥情空心
滥情空心 2021-01-04 03:51

i\'m working with the youtube json from google-api-client :

{
    \"apiVersion\": \"2.0\",
    \"data\": {
        \"updated\": \"2011-01-05T13:48:33.146Z\",         


        
3条回答
  •  青春惊慌失措
    2021-01-04 04:24

    Just say it from my personal experience, @Key may not work on serialization/de-serialization when choosing the wrong Json parser.

    (1) When you use Gson parser, like below :

    GsonBuilder gsb = new GsonBuilder();
    Gson gson = gsb.create();
    OneDriveItem oneDriveItem = gson.fromJson(jasonData1, OneDriveItem.class);
    

    @Key does not work, you should use @SerializedName to annotate the field name.

    (2) When you use JsonFactory from the package com.google.api.client.json, like below :

     JacksonFactory jsonFactory=new JacksonFactory();
    

    @Key should work.

提交回复
热议问题