spring data mongodb: how to set default value for entity?

143 Views Asked by At

We have document in mongodb db

{_id: xxx, my_field: null}

and spring-data-mongodb entity:

@Document
class Test () {
    @Id
    open var id: ObjectId = ObjectId()

    @Field("my_field")
    var my_field: Boolean = false
}

It worked on the spring 2.x, but after update up to 3.x it now leads to an errors like:

java.lang.NullPointerException: Cannot invoke "java.lang.Number.intValue()" because the return value of "sun.invoke.util.ValueConversions.primitiveConversion(sun.invoke.util.Wrapper, Object, boolean)" is null
    at java.base/sun.invoke.util.ValueConversions.unboxBoolean(ValueConversions.java:108) ~[na:na]

It is possible to return old behavior? (without updaing collection, it's difficult now)

0

There are 0 best solutions below