I'm trying to map an immutable object from MongoDB to my Java POJO and i keep getting the following error:
org.springframework.web.util.NestedServletException:
Request processing failed;
nested exception is java.lang.RuntimeException:
org.mongodb.morphia.mapping.MappingException:
No usable constructor for com.example.model.Item
It seems that when using immutable objects, I need to annotate using @BsonCreator however that doesn't appear to be working and I believe that might be because using this annotation requires me to somehow configure org.bson.codecs.pojo.Conventions#ANNOTATION_CONVENTION
. Maybe I'm blind but i can't seem to find any examples anywhere on how to configure this. Any help would be greately appreciated. Here is my annotated POJO:
@Value /* Lombok auto generates getters */
@Builder /* Lombok auto generates builder method */
public class Item implements Serializable {
private final @NotNull AnEnum type;
private final int refId;
private final int quantity;
@BsonCreator
public Item(@BsonProperty("type") AnEnum type,
@BsonProperty("refId") int refId,
@BsonProperty("quantity") int quantity) {
this.type = type;
this.refId = refId;
this.quantity = quantity;
}
}