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

com.mageddo.common.jackson.converters.MonetaryConverter Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.mageddo.common.jackson.converters;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.mageddo.common.monetary.Monetary;

import java.io.IOException;

public interface MonetaryConverter {

	class MonetaryJsonDeserializer extends JsonDeserializer {
		@Override
		public Monetary deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
			final String value = p.getValueAsString();
			if (value == null) {
				return null;
			}
			return new Monetary(value);
		}
	}

	class MonetaryJsonSerializer extends JsonSerializer {
		@Override
		public void serialize(Monetary value, JsonGenerator gen, SerializerProvider p) throws IOException {
			if (value == null) {
				gen.writeNull();
			} else {
				gen.writeString(String.valueOf(value));
			}
		}
	}

	class MonetaryDisplaySerializer extends JsonSerializer {
		@Override
		public void serialize(Monetary value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
			if (value == null) {
				gen.writeNull();
			} else {
				gen.writeString(value.toDisplayString());
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy