Home > Software design >  Artifact to use for @BsonIgnore
Artifact to use for @BsonIgnore

Time:10-08

I am attempting to abstract out my core objects for a service I am writing to a library. I have all the other artifacts I need straightened out, but unfortunately I cannot find an artifact for @BsonIgnore. I am using @BsonIgnore to ignore some methods that get added to the bson document when they shouldn't, as the implementing service writes these objects to MongoDb.

For context, the service is written using Quarkus, and Mongo objects are handled with Panache:

implementation 'io.quarkus:quarkus-mongodb-panache'

The library I am creating is mostly just a simplistic pojo library, nothing terribly fancy in the Gradle build.

I have found this on Maven Central: https://mvnrepository.com/artifact/org.bson/bson?repo=novus-releases but seems like not a normal release, and doesn't solve the issue.

In case it is useful, here is my code:

@Data
public abstract class Historied {
    /** The list of history events */
    private List<HistoryEvent> history = new ArrayList<>(List.of());

    /**
     * Adds a history event to the set held, to the front of the list.
     * @param event The event to add
     * @return This historied object.
     */
    @JsonIgnore
    public Historied updated(HistoryEvent event) {
        if(this.history.isEmpty() && !EventType.CREATE.equals(event.getType())){
            throw new IllegalArgumentException("First event must be CREATE");
        }
        if(!this.history.isEmpty() && EventType.CREATE.equals(event.getType())){
            throw new IllegalArgumentException("Cannot add another CREATE event type.");
        }

        this.getHistory().add(0, event);
        return this;
    }

    @BsonIgnore
    @JsonIgnore
    public HistoryEvent getLastHistoryEvent() {
        return this.getHistory().get(0);
    }

    @BsonIgnore
    @JsonIgnore
    public ZonedDateTime getLastHistoryEventTime() {
        return this.getLastHistoryEvent().getTimestamp();
    }
}

CodePudding user response:

This is the correct dependency https://mvnrepository.com/artifact/org.mongodb/bson/4.3.3, but check for your specific version

  • Related