Search in sources :

Example 1 with StoredAsJson

use of com.hubspot.rosetta.annotations.StoredAsJson in project Rosetta by HubSpot.

the class StoredAsJsonBeanSerializerModifier method changeProperties.

@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
    for (BeanPropertyWriter beanProperty : beanProperties) {
        StoredAsJson storedAsJson = beanProperty.getAnnotation(StoredAsJson.class);
        if (storedAsJson != null && !StoredAsJson.NULL.equals(storedAsJson.empty())) {
            final JsonSerializer<Object> nullSerializer;
            if (storedAsJson.binary()) {
                nullSerializer = new ConstantBinarySerializer(storedAsJson.empty());
            } else {
                nullSerializer = new ConstantSerializer(storedAsJson.empty());
            }
            beanProperty.assignNullSerializer(nullSerializer);
        }
    }
    return super.changeProperties(config, beanDesc, beanProperties);
}
Also used : BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) StoredAsJson(com.hubspot.rosetta.annotations.StoredAsJson)

Aggregations

BeanPropertyWriter (com.fasterxml.jackson.databind.ser.BeanPropertyWriter)1 StoredAsJson (com.hubspot.rosetta.annotations.StoredAsJson)1