Hi,
I have a collection where the documents contain a Time
value in them such as the following simplified document:
{
"ref": Ref(Collection("dateexamples"), "101"),
"ts": 1646429154220000,
"data": {
"creationDate": Time("2022-03-04T21:25:54.106843Z")
}
}
And I have a Java object that the data
and specifically the creationDate
should be transformed into as follows (without the usual boilerplate):
public class DateExample {
private ZonedDateTime creationDate;
}
So when I do something like (abbreviated for readability)
Value result = client.query( ... ).get();
DateExample dateExample = result.to(DateExample.class).get();
I would expect the Fauna Time
to be converted to a ZonedDateTime
however this doesn’t work; in fact I have been through the different Java Date like classes and have found the following:
Library | Class | Result |
---|---|---|
Core Java | java.time.ZonedDateTime |
com.faunadb.client.errors.FaunaException: No suitable constructor or factory method found for type java.time.ZonedDateTime. Ensure that a factory method or constructor is annotated with @FaunaConstructor at com.faunadb.client.types.Constructors.createDecoder(Constructors.java:37) |
Core Java | java.time.LocalDateTime |
com.faunadb.client.errors.FaunaException: No suitable constructor or factory method found for type java.time.LocalDateTime. Ensure that a factory method or constructor is annotated with @FaunaConstructor at com.faunadb.client.types.Constructors.createDecoder(Constructors.java:37) |
Core Java | java.util.GregorianCalendar |
java.lang.ClassCastException: class com.faunadb.client.types.Value$TimeV cannot be cast to class com.faunadb.client.types.Value$ObjectV (com.faunadb.client.types.Value$TimeV and com.faunadb.client.types.Value$ObjectV are in unnamed module of loader 'app') at com.faunadb.client.types.Constructors$AbstractConstructorDecoder.apply(Constructors.java:144) |
Core Java | java.util.Date |
java.lang.ClassCastException: class com.faunadb.client.types.Value$TimeV cannot be cast to class com.faunadb.client.types.Value$ObjectV (com.faunadb.client.types.Value$TimeV and com.faunadb.client.types.Value$ObjectV are in unnamed module of loader 'app') at com.faunadb.client.types.Constructors$AbstractConstructorDecoder.apply(Constructors.java:144) |
JodaTime | org.joda.time.DateTime |
java.lang.ClassCastException: class com.faunadb.client.types.Value$TimeV cannot be cast to class com.faunadb.client.types.Value$ObjectV (com.faunadb.client.types.Value$TimeV and com.faunadb.client.types.Value$ObjectV are in unnamed module of loader 'app') at com.faunadb.client.types.Constructors$AbstractConstructorDecoder.apply(Constructors.java:144) |
I think the native Java date type types should be supported out of the box (at least the java.time.*
ones). However I would also be happy to write a converter (is this a Codec/Encoder/Decoder?) and register them with the Fauna Java driver but I can’t figure out how to accomplish this.
So I guess the questions are:
Am I missing something and the above types should work with the correct configuration?
If not:
How can I register some kind of custom converter with the Fauna driver?
Could the Jackson De/Serialisers help?
Any help/pointers would be appreciated. Thanks in advance.