Search in sources :

Example 1 with BsonIgnore

use of org.bson.codecs.pojo.annotations.BsonIgnore in project mongo-java-driver by mongodb.

the class ConventionAnnotationImpl method processPropertyAnnotations.

private void processPropertyAnnotations(final ClassModelBuilder<?> classModelBuilder, final PropertyModelBuilder<?> propertyModelBuilder) {
    for (Annotation annotation : propertyModelBuilder.getReadAnnotations()) {
        if (annotation instanceof BsonProperty) {
            BsonProperty bsonProperty = (BsonProperty) annotation;
            if (!"".equals(bsonProperty.value())) {
                propertyModelBuilder.readName(bsonProperty.value());
            }
            propertyModelBuilder.discriminatorEnabled(bsonProperty.useDiscriminator());
            if (propertyModelBuilder.getName().equals(classModelBuilder.getIdPropertyName())) {
                classModelBuilder.idPropertyName(null);
            }
        } else if (annotation instanceof BsonId) {
            classModelBuilder.idPropertyName(propertyModelBuilder.getName());
        } else if (annotation instanceof BsonIgnore) {
            propertyModelBuilder.readName(null);
        } else if (annotation instanceof BsonRepresentation) {
            BsonRepresentation bsonRepresentation = (BsonRepresentation) annotation;
            BsonType bsonRep = bsonRepresentation.value();
            propertyModelBuilder.bsonRepresentation(bsonRep);
        }
    }
    for (Annotation annotation : propertyModelBuilder.getWriteAnnotations()) {
        if (annotation instanceof BsonProperty) {
            BsonProperty bsonProperty = (BsonProperty) annotation;
            if (!"".equals(bsonProperty.value())) {
                propertyModelBuilder.writeName(bsonProperty.value());
            }
        } else if (annotation instanceof BsonIgnore) {
            propertyModelBuilder.writeName(null);
        }
    }
}
Also used : BsonType(org.bson.BsonType) BsonId(org.bson.codecs.pojo.annotations.BsonId) BsonRepresentation(org.bson.codecs.pojo.annotations.BsonRepresentation) BsonProperty(org.bson.codecs.pojo.annotations.BsonProperty) Annotation(java.lang.annotation.Annotation) BsonIgnore(org.bson.codecs.pojo.annotations.BsonIgnore)

Aggregations

Annotation (java.lang.annotation.Annotation)1 BsonType (org.bson.BsonType)1 BsonId (org.bson.codecs.pojo.annotations.BsonId)1 BsonIgnore (org.bson.codecs.pojo.annotations.BsonIgnore)1 BsonProperty (org.bson.codecs.pojo.annotations.BsonProperty)1 BsonRepresentation (org.bson.codecs.pojo.annotations.BsonRepresentation)1