Can you annotate to not save field if it is null?

27 views
Skip to first unread message

Tony Park

unread,
May 27, 2024, 5:29:31 PMMay 27
to objectify-appengine
Is there a way to annotate a field so that it will not be saved in Datastore if the value is null?

Be default, a field is saved (serialized) if it is null and appears as "null" in the Datastore explorer in the web browser.

I tried using Jackson like this but it didn't work:
@JsonInclude(Include.NON_NULL)
private String text;

Jeff Schnitzer

unread,
May 27, 2024, 6:25:56 PMMay 27
to objectify-appengine
Are you looking for this?

@IgnoreSave(IfNull.com)

--
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/a01efbda-bead-485c-8b24-899a6ffc6966n%40googlegroups.com.

Jeff Schnitzer

unread,
May 27, 2024, 6:27:04 PMMay 27
to objectify-appengine
Sorry I'm on my phone. That's IfNull.class

Tony Park

unread,
May 27, 2024, 7:34:47 PMMay 27
to objectify-appengine
That looks like it should work. I see there are many other useful conditions to pass in as well. Thank you.

Tony Park

unread,
May 27, 2024, 10:25:20 PMMay 27
to objectify-appengine
It looks like you can't put @IgnoreSave(IfNull.class) at the top of the class to apply to all the fields in a class. It is only possible to put it on one field at a time. That's fine but it would be less cluttered to have a one liner.

Would it be possible to make @IgnoreSave(IfNull.class) apply to @Target({ElementType.TYPE, ElementType.FIELD})?

Jeff Schnitzer

unread,
May 28, 2024, 12:28:42 AMMay 28
to objectify...@googlegroups.com
You aren't wrong. Can you add this as a feature request in the github issues?

Jeff

Reply all
Reply to author
Forward
0 new messages