package com.gfi.serializer;

import java.io.IOException;

import java.math.BigDecimal;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.gfi.constants.Constants;
import com.gfi.utils.Utilities;

/**
 * JsonImporteSerializer.
 * 
 *  
 */
public class JsonImporteSerializer extends JsonSerializer<BigDecimal> {

	/**
	 * Serializador para importes. Siempre serializa importes con dos decimales.
	 * 
	 * @param importe
	 *            BigDecimal
	 * @param jsonGenerator
	 *            JsonGenerator
	 * @param paramSerializerProvider
	 *            SerializerProvider
	 * @throws IOException
	 *             e
	 * @throws JsonProcessingException
	 *             e
	 * 
	 */
	@Override
	public void serialize(BigDecimal importe, JsonGenerator jsonGenerator, SerializerProvider paramSerializerProvider)
			throws IOException {
		jsonGenerator.writeString(Utilities.formatImporteToString(importe, Constants.DECIMALES_EURO));
	}
}