DateTimeOffset
is actually a dumb Date
wrapper. Here he is completely.
public class DateTimeOffset extends Date { public DateTimeOffset(Date date) { this.setTime(date.getTime()); } }
I raised my hands up and just decided instead to use Strings and the DateTime class of joda-time via DateTime.parse(string)
to process them.
However, a good alternative is probably to register your own serializer with MobileServiceClient.registerSerializer(...)
, but you will not get anything useful in using your wrapper.
This SDK is trash.
edit: Using a custom (de) serializer seems to work quite well:
private class DateTimeSerialiser implements JsonSerializer<DateTime>, JsonDeserializer<DateTime> { @Override public JsonElement serialize(final DateTime src, final Type typeOfSrc, final JsonSerializationContext context) { return new JsonPrimitive(src.toString()); } @Override public DateTime deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { return DateTime.parse(json.getAsString()); } }
Set it to deserialize / serialize to / from the object of your choice, then set its instance using MobileServiceClient.registerSerializer + registerDeserializer
. If you use local synchronization, just use ColumnDataType.String
or ColumnDataType.DateTimeOffset
(it's just a line under the hood). Now you can specify your field in the type you need.
private DateTime date;
source share