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

com.fasterxml.jackson.module.scala.ser.ScalaIterableSerializer.scala Maven / Gradle / Ivy

Go to download

Add-on module for Jackson (http://jackson.codehaus.org) to support Scala (http://www.scala-lang.org/) data types.

There is a newer version: 1.9.3
Show newest version
package com.fasterxml.jackson.module.scala.ser

import org.codehaus.jackson.map._
import org.codehaus.jackson._
import ser.ContainerSerializerBase

/**
 * The implementation is taken from the code written by Greg Zoller, found here:
 * http://jira.codehaus.org/browse/JACKSON-211
 */
class ScalaIterableSerializer extends ContainerSerializerBase[Iterable[Any]](classOf[Iterable[Any]]) {
	override def serialize(value:Iterable[Any], jgen:JsonGenerator, provider:SerializerProvider) {
		jgen.writeStartArray();
		if( value.size > 0 ) {
			value.foreach( x =>
				provider.findValueSerializer(x.asInstanceOf[AnyRef].getClass).serialize(x.asInstanceOf[AnyRef], jgen, provider)
			)
		}
		jgen.writeEndArray();
	}
	override def _withValueTypeSerializer(vts:TypeSerializer) = new ScalaIterableSerializer()
	override def getSchema(provider:SerializerProvider, typeHint:java.lang.reflect.Type) = createSchemaNode("string", true)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy