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

com.ppiech.auto.value.jackson.internal.objectmappers.IntegerMapper Maven / Gradle / Ivy

package com.ppiech.auto.value.jackson.internal.objectmappers;

import com.ppiech.auto.value.jackson.JsonMapper;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

import java.io.IOException;

/**
 * Built-in mapper for Integer objects
 */
public class IntegerMapper extends JsonMapper {

    @Override
    public Integer parse(JsonParser jsonParser) throws IOException {
        if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
            return null;
        } else {
            return jsonParser.getIntValue();
        }
    }

    @Override
    public void parseField(Integer instance, String fieldName, JsonParser jsonParser) throws IOException { }

    @Override
    public void serialize(Integer object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
        generator.writeNumber(object);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy