I am using Azure Mobile Apps SDK for Android.
public class MyClass {
public String Id;
public String Code;
public DateTimeOffset ClientCreatedAt;
}
MyClass myClass = new MyClass();
myClass.Id = "1234567890";
myClass.Code = "dfgdrvyet";
myClass.ClientCreatedAt = new DateTimeOffset(new Date());
It is being used as follows:
MobileServiceSyncTable<MyClass> myClassSyncTable = _client.getSyncTable(MyClass.class);
ListenableFuture<MyClass> responseFuture = myClassSyncTable.insert(myClass);
Upon insertion, the ClientCreatedAt
is set to null, when I investigated the insert statement, it is the Gson within the library that is not serialising the DatetimeOffset, specifically, this line:
JsonObject json = mClient.getGsonBuilder().create().toJsonTree(item).getAsJsonObject();
When I replace the DateTimeOffset
with Date
, the value is serialised properly.
So, my questions are:
- Is it intended in Azure Mobile Apps for me to use the DateTimeOffset and if so, what is the right way to use it?
- Can I force Gson to serialise the DateTimeOffset properly? I looked at the Gson Annotations, but nothing that can help there. I am not sure if I should be creating a getter and a setter for serialising and deserialising.