逆の方法で使用したのとまったく同じ方法を使用します(@SerializedName
)。
package net.sargue.gson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import org.intellij.lang.annotations.Language;
public class SO36488332 {
public static void main(String[] args) {
@Language("JSON")
String json = "{\n" +
" \"318\": \"I am a String.\"\n" +
"}";
Gson gson = new GsonBuilder().create();
MyPOJO myPOJO = gson.fromJson(json, MyPOJO.class);
System.out.println("myPOJO.threeOneEight = " + myPOJO.threeOneEight);
}
private static class MyPOJO {
@SerializedName("318")
private String threeOneEight;
}
}
実行結果は次のとおりです:
myPOJO.threeOneEight = I am a String.
この
チェック