io.knowledgelinks.cicd.semantic.versioning.config.ConfigurationSerializer Maven / Gradle / Ivy
package io.knowledgelinks.cicd.semantic.versioning.config;
import java.io.IOException;
import java.util.Map.Entry;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
public class ConfigurationSerializer extends StdSerializer {
private static final long serialVersionUID = -6711538273419285921L;
public ConfigurationSerializer() {
this(null);
}
public ConfigurationSerializer(Class t) {
super(t);
}
@Override
public void serialize(Configuration value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
gen.writeStartObject();
for (Entry item : value.configurableFields.entrySet()) {
if (item.getValue().getType() == Integer.class) {
gen.writeNumberField(item.getKey(), item.getValue().getIntValue());
} else {
gen.writeStringField(item.getKey(), item.getValue().getStringValue());
}
}
gen.writeEndObject();
}
}