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

com.fasterxml.jackson.databind.ext.CoreXMLSerializers Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
package com.fasterxml.jackson.databind.ext;

import java.io.IOException;
import java.lang.reflect.Type;

import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.fasterxml.jackson.databind.ser.std.CalendarSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

/**
 * Provider for serializers of XML types that are part of full JDK 1.5, but
 * that some alleged 1.5 platforms are missing (Android, GAE).
 * And for this reason these are added using more dynamic mechanism.
 *

* Note: since many of classes defined are abstract, caller must take * care not to just use straight equivalency check but rather consider * subclassing as well. */ public class CoreXMLSerializers extends Serializers.Base { @Override public JsonSerializer findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) { Class raw = type.getRawClass(); if (Duration.class.isAssignableFrom(raw) || QName.class.isAssignableFrom(raw)) { return ToStringSerializer.instance; } if (XMLGregorianCalendar.class.isAssignableFrom(raw)) { return XMLGregorianCalendarSerializer.instance; } return null; } public static class XMLGregorianCalendarSerializer extends StdSerializer { public final static XMLGregorianCalendarSerializer instance = new XMLGregorianCalendarSerializer(); public XMLGregorianCalendarSerializer() { super(XMLGregorianCalendar.class); } @Override public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } @Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return CalendarSerializer.instance.getSchema(provider, typeHint); } @Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy