My Spring-Boot & Couchbase app has a Cat object in the DB.
In a new app version, we added new boolean field to out Cat document object:
@RequiredArgsConstructor
@AllArgsConstructor(onConstructor = @__(@PersistenceConstructor))
@Document
@Data
@Builder
@EqualsAndHashCode
public class Cat {
....
@Field
final boolean isHungry
But now, we already have Cat objects that are in the DB and don't have this field.
When the app is trying to read these Cats we get this error:
org.springframework.data.mapping.model.MappingInstantiationException: Failed
to instantiate com.example.Cat using constructor public
com.example.Cat(...) with arguments ...
...
Caused by: java.lang.IllegalArgumentException: Parameter isHungry must not be null!
Isn't there a way to tell Spring that if the field is missing in the DB, it should use a default value (false in this case)
Try making a constructor with all parameters except isHungry, and set isHungry to false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With