de.bild.codec.ReflectionCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of polymorphia Show documentation
Show all versions of polymorphia Show documentation
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
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);
}
}
}
}