1

I have the following classes for two models:

public class A extends RealmObject {
    private String field1;
    private B field2;

    //getters and setters
    //...
}

public class B extends RealmObject {
    private String field3;
    private Date field4;

    //getters and setters
    //...
}

I am receiving the following JSON that corresponds to the models:

{
    "field1" : "hi",
    "field2" : {
        "field3" : "hi again",
        "field4" : "2015-02-17T00:00:00"
    }
}

I am trying to create an A object from the JSON, using createObjectFromJson(A.class, jsonString), but I am getting an exception java.lang.NumberFormatException: Invalid long: "2015-02-17T00:00:00".

It seems that realm is considering the date as a long instead of a String. Is there a way to set some kind of date format?

gookman
  • 2,527
  • 2
  • 20
  • 28

1 Answers1

1

Realm only supports two kinds of date formats just yet. You can see them here: https://github.com/realm/realm-java/blob/master/realm/src/main/java/io/realm/internal/android/JsonUtils.java

We do however plan to add support for ISO8061 date formats like yours when we implement V2 of the JSON API. You can follow progress on that here: https://github.com/realm/realm-java/issues/682

Until then you will have to convert your timestamps manually or use GSON's dateformatters: GSON - Date format

Community
  • 1
  • 1
Christian Melchior
  • 19,978
  • 5
  • 62
  • 53