JSON(StartDate = / Date(1341348517698 + 0200)/)として提供されるDateTime(C#)をgsonを使用してAndroidカレンダーオブジェクトに逆シリアル化しようとしています...
私はすでに次のことを試みましたが成功しませんでした:
ObjectWithCalender cal = gson.fromJson(jsonWithDate, ObjectWithCalender.class);
Date 用のカスタム デシリアライザーを作成する必要があります。たとえば、このクラスを作成します。
public class DotNetDateDeserializer implements JsonDeserializer<Date> {
@Override
public Date deserialize(JsonElement json, Type typfOfT, JsonDeserializationContext context) {
// this is the place where you convert .NET timestamp into Java Date object
}
}
次に、JSON 文字列を POJO に変換する前に:
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new DotNetDateDeserializer());
Gson gson = builder.create();
gson.fromJson(jsonString, Class);
datetime の代わりに UNIX タイムスタンプを使用します。datetime はあいまいな構造体です