morphia icon indicating copy to clipboard operation
morphia copied to clipboard

Override isStoreNulls in PropertyAnnotation

Open chaseberry opened this issue 9 years ago • 1 comments

Sometimes it can be useful to store a null value. While 99% of the time I don't, there are several times I want to null something out. It would be useful to have a field which can store/not store nulls overriding the default value of the mapper option

@Property(storeNull = true) String name; @Property(storeNull = false) lateinit var name:String

chaseberry avatar Feb 25 '16 15:02 chaseberry

I'm slow getting to this i know but I'm starting to looking at next version issues. The problem with using @Property is the default value for boolean has to be true or false. How do I express that generally I want to store nulls but on this field I don't? How does one determine a non-answer (a value wasn't configured and so the general mapping rules apply)?

We could define that value using a String and then parse out values from "true" and "false". But that feels awkward. We could use a special annotation just for this: @StoreNulls. Oh, but I want the opposite so I guess, @DoNotStoreNulls. But what about empties? Do I get @StoreEmpties and @DoNotStoreEmpties?

I'm inclined to close this as won't fix. It introduces complexity for a very niche feature. It sounds like what you really need here is a lifecycle event to, perhaps, add that field with a null value in the Document before it gets persisted to the database.

evanchooly avatar Nov 05 '20 04:11 evanchooly