Improve compatiblity with kotlin

66 views
Skip to first unread message

frederik...@gmail.com

unread,
Jun 29, 2021, 10:42:57 AM6/29/21
to objectify-appengine
Hi,

any ideas how to solve the following problems with kotlin?

Objectify needs a no-arg constructor, however models benefit from kotlins data class which only has a no-arg constructor when a default value is supplied for each field. This is especially difficult for Refs. You kinda have to make them nullable to provide a default value.

You cannot use vals because Objectify does not make use of field constructors and therefore cannot change vals to the assigned values.

Best regards and thanks in advance!
Frederik

Jeff Schnitzer

unread,
Jun 29, 2021, 5:11:02 PM6/29/21
to objectify-appengine
That's a tough one. It's not impossible - probably it would require creating a metamodel, filling it dynamically using something like the current logic, then using constructors to create the final pojos. Actually, there are some impossible things - there can be loops and self-references and all sorts of interesting structures in the loaded entity. I don't think you could put this together without some fields being mutable.

It would be an insane amount of work to try.

Jeff

--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/objectify-appengine/96961cc0-74fa-4881-ae4c-a9c960a1f8f8n%40googlegroups.com.

frederik...@gmail.com

unread,
Jun 30, 2021, 11:18:25 AM6/30/21
to objectify-appengine
I thought of a custom Transformer like those used in gson/jackson. You get  the data from the datastore and can manually create your object. I don't think this is currently supported by objectify v6? Other than that it's probably best to stick to mutable values and non-null safety.

frederik...@gmail.com

unread,
Jun 30, 2021, 11:20:08 AM6/30/21
to objectify-appengine
Regarding objectify automatically using the right non-no-arg constructor, maybe kotlinx.serialization from jetebrains could give some good ideas how to use kotlin with serialization.
Reply all
Reply to author
Forward
0 new messages