package de.fesere.hypermedia.cj.serialization;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import de.fesere.hypermedia.cj.model.data.*;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

public class DataEntrySerializer extends StdSerializer<DataEntry> {
    protected DataEntrySerializer() {
        super(DataEntry.class);
    }

    @Override
    public void serialize(DataEntry value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
        if (value instanceof EmptyDataEntry) {
            return;
        }
        jgen.writeStartObject();

        writeName(value, jgen);
        writeValue(value, jgen);
        writePrompt(value, jgen);

        jgen.writeEndObject();

    }

    private void writePrompt(DataEntry value, JsonGenerator jgen) throws IOException {
        String prompt = value.getPrompt();
        if (StringUtils.isNotBlank(prompt)) {
            jgen.writeStringField("prompt", prompt);
        }
    }

    private void writeName(DataEntry value, JsonGenerator jgen) throws IOException {
        jgen.writeStringField("name", value.getName());
    }

    private void writeValue(DataEntry value, JsonGenerator jgen) throws IOException {
        jgen.writeFieldName("value");
        writeContent(value, jgen);
    }


    private void writeContent(DataEntry value, JsonGenerator jgen) throws IOException {
        if (value instanceof StringDataEntry) {
            StringDataEntry stringEntry = (StringDataEntry) value;
            jgen.writeString(stringEntry.getValue());
        } else if (value instanceof NumberDataEntry) {
            writeNumber((NumberDataEntry) value, jgen);
        } else if (value instanceof BooleanDataEntry) {
            jgen.writeBoolean((boolean) value.getValue());
        } else {
            jgen.writeString((String) value.getValue());
        }
    }

    private void writeNumber(NumberDataEntry value, JsonGenerator jgen) throws IOException {
        Number number = value.getValue();
        if (number instanceof Double) {
            jgen.writeNumber(number.doubleValue());
        } else {
            jgen.writeNumber(number.intValue());
        }
    }
}
package de.fesere.hypermedia.cj.serialization;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import de.fesere.hypermedia.cj.exceptions.SerializationException;
import de.fesere.hypermedia.cj.model.data.*;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

public class DataEntrySerializer extends StdSerializer<DataEntry> {

    private JsonGenerator jgen;

    protected DataEntrySerializer() {
        super(DataEntry.class);
    }

    @Override
    public void serialize(DataEntry entry, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
        if (entry instanceof EmptyDataEntry) {
            return;
        }
        this.jgen = jgen;

        jgen.writeStartObject();

        writeName(entry.getName());
        writeValue(entry.getValue());
        writePrompt(entry.getPrompt());

        jgen.writeEndObject();

    }

    private void writeName(String name) throws IOException {
        jgen.writeStringField("name", name);
    }

    private void writeValue(Object value) throws IOException {
        jgen.writeFieldName("value");
        writeContent(value);
    }


    private void writeContent(Object value) throws IOException {
        if (value instanceof String) {
            jgen.writeString((String) value);
        } else if (value instanceof Number) {
            Number number = (Number) value;
            writeNumber(number);
        } else if (value instanceof Boolean) {
            jgen.writeBoolean((boolean) value);
        } else if (value == null) {
            jgen.writeNull();
        }
        else {
            throw new SerializationException("Unspoorted value of type " + value.getClass().getCanonicalName() );
        }
    }

    private void writeNumber(Number number) throws IOException {
        if (number instanceof Double) {
            jgen.writeNumber(number.doubleValue());
        } else {
            jgen.writeNumber(number.intValue());
        }
    }

    private void writePrompt(String prompt) throws IOException {
        if (StringUtils.isNotBlank(prompt)) {
            jgen.writeStringField("prompt", prompt);
        }
    }
}
Clean up the parameters and method names