com.fasterxml.jackson.module.scala.ser.ScalaIterableSerializer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-scala Show documentation
Show all versions of jackson-module-scala Show documentation
Add-on module for Jackson (http://jackson.codehaus.org) to support
Scala (http://www.scala-lang.org/) data types.
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)
}