All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.bild.codec.ReflectionCodec Maven / Gradle / Ivy

Go to download

A very fast POJO codec for MongoDB (used in conjunction with the Mongo Java Driver) that handles generic types as well as polymorphic class hierarchies

There is a newer version: 2.8.2
Show newest version
package de.bild.codec;

import java.util.Map;
import java.util.Set;


/**
 * Used by Polymorphia internally to tag codecs that use reflection to build a Codec for al properties
 * @param 
 */
public interface ReflectionCodec extends PolymorphicCodec {
    Map getPersistenceFields();

    MappedField getMappedField(String mappedFieldName);

    /**
     * Called after entity has been decoded
     * @param instance
     */
    void postDecode(T instance);

    /**
     * Called just before encoding
     * @param instance
     */
    void preEncode(T instance);

    @Override
    default void verifyFieldsNotNamedLikeAnyDiscriminatorKey(Set propertyNames) throws IllegalArgumentException {
        for (String propertyName : propertyNames) {
            MappedField mappedField = getMappedField(propertyName);
            if (mappedField != null) {
                LOGGER.error("A field {} within {} is named like one of the discriminator keys {}", mappedField.getMappedFieldName(), getEncoderClass(), propertyNames);
                throw new IllegalArgumentException("A field " + mappedField.getMappedFieldName() + " within " + getEncoderClass() + " is named like one of the discriminator keys " + propertyNames);

            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy