I don't know how to archive @SerializedName("user.f_name")as a path,
but the smoothed inner field is archived thanks JsonDeserializer.
Let's pretend that
{
"publishDate": {
__type: "Date",
iso: "2014-11-05T02:27:00.000Z"
},
...
}
and we want to convert the internal "iso" field to the top "publishDate" as Date.
, JsData .
public class JsData {
public Date publishDate;
...
}
JsonDeserializer<Date> gson . gson Date, .
public static class PublishDateDeserializer implements JsonDeserializer<Date> {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String iso = json.getAsJsonObject().get("iso").getAsString();
DateFormat parser = new SimpleDateFormat(DATE_JSON_PATTERN);
try {
return parser.parse(iso);
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
}
builder
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new PublishDateDeserializer()).create();
gson.fromJson(json, JsData.class);
, .