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

website.automate.waml.io.serliazer.ParentCriteriaSerializer Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package website.automate.waml.io.serliazer;


import java.io.IOException;

import website.automate.waml.io.model.action.ParentCriteria;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.ResolvableSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

public class ParentCriteriaSerializer extends StdSerializer implements ResolvableSerializer {

    private static final long serialVersionUID = 7861146712268855092L;
    
    @SuppressWarnings("rawtypes")
    private final JsonSerializer defaultSerializer;
    
    @SuppressWarnings("rawtypes") 
    public ParentCriteriaSerializer(JsonSerializer defaultSerializer) {
        super(ParentCriteria.class);
        this.defaultSerializer = defaultSerializer;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public void serialize(ParentCriteria parentCriteria, JsonGenerator generator,
            SerializerProvider provider) throws IOException {
        if(parentCriteria.canBeShortNotated()){
            Object defaultCriterionValue = parentCriteria.getDefaultCriterionValue();
            generator.writeObject(defaultCriterionValue);
        } else {
            defaultSerializer.serialize(parentCriteria, generator, provider);
        }
    }

    @Override
    public void resolve(SerializerProvider provider)
            throws JsonMappingException {
        ((ResolvableSerializer) defaultSerializer).resolve(provider);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy