I have an abstract class describing a mongo document. There could be different implementations of this class that need to override an abstract method. Here is a simplified example:
@Document
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
public abstract class Entity {
@Id
private ObjectId id;
abstract String getSomething();
}
I want getSomething()
to be written to the document as a string field. But I don't want to read it back.
I've tried to use the @AccessType
annotation:
@AccessType(AccessType.Type.PROPERTY)
abstract String getSomething();
But when I'm reading this document from the db, spring throws UnsupportedOperationException: No accessor to set property
. It is trying to find a setter for this field, but I don't want to define a setter for it - the method may return a calculated value and there should be no ability to change it. Although an empty setter could help, it looks more like a workaround, and I would try to avoid it.
So I'm wondering if there is a way to skip this particular property when reading from the db? Something opposite to the @Transient
annotation. Or similar to @JsonIgnore
in the Jackson library.