Support for ZonedDateTime (Java 8)

754 views
Skip to first unread message

Faliorn

unread,
May 10, 2014, 2:59:44 PM5/10/14
to mor...@googlegroups.com
Hi all! This is Faliorn, from Spain.

First, I'd like to thank everyone working on Morphia. I've been working on a MongoDB test project, and it works great!

However, now I'd need to add Java 8's ZonedDateTime support. As far as I know, there are custom converters (maybe extending TypeConverter), but I don't know exactly how to do it. A brief explanation or a link to the documentation would be just fine. I've tried to find it myself but with no luck so far.

Also, I've been a Java developer for about 12 years, with projects involving JPA 2 and hibernate. Now I'm gettind deep into MongoDB world. So, I'd be willing to contribute if you think I can help you in any way.

Best regards!

Faliorn

Justin Lee

unread,
May 12, 2014, 9:10:23 AM5/12/14
to mor...@googlegroups.com
I just wrote one for LocalDateTime for one of my many side projects.  You can find that here:  https://github.com/evanchooly/javabot/blob/master/core/src/main/java/javabot/dao/util/LocalDateTimeConverter.java.  Once you have it defined, you can register like you see here:  https://github.com/evanchooly/javabot/blob/784f7f31fa5edde347d5d49b9a24aac973d4d003/core/src/main/java/javabot/JavabotModule.java#L59

As a side note, try not to pay too much attention to the other code there.  That project is a playground for learning new stuff and i've been overengineering it back and forth for over a decade now so it's accumulated more cruft than I care to think about.  :)

Anyway, I hope that helps get you over the hump.  Feel free to follow up if not.



--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Faliorn

unread,
May 13, 2014, 6:20:03 AM5/13/14
to mor...@googlegroups.com
Thanks Justin! That's very useful and just what I was looking for.

I made my own ZonedDateTimeConverter in the same basis of the one you sent and so far, so good. I haven't made strong testing on it yet, but it seems to work just fine.

Best regards!
Reply all
Reply to author
Forward
0 new messages