Improved support for custom collections in Lift JSON #1079

Closed
jonifreeman opened this Issue Jul 28, 2011 · 2 comments

Comments

Projects
None yet
2 participants
Member

jonifreeman commented Jul 28, 2011

It is currently not possible to provide a custom serializer for collection types. Adding support for IndexedSeq's for instance does not work now:


class IndexedSeqSerializer extends Serializer[IndexedSeq[_]] {
  def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), IndexedSeq[_]] = {
    case (TypeInfo(clazz, ptype), json) if classOf[IndexedSeq[_]].isAssignableFrom(clazz) => json match {
      case JArray(xs) => 
        val t = ptype.getOrElse(throw new MappingException("parameterized type not known"))
        xs.map(x => Extraction.extract(x, TypeInfo(t.getActualTypeArguments()(0).asInstanceOf[Class[_]], None))).toIndexedSeq
      case x => throw new MappingException("Can't convert " + x + " to IndexedSeq")
    }
  }

  def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
    case i: IndexedSeq[_] => JArray(i.map(Extraction.decompose).toList)
  }
}
Member

jonifreeman commented Aug 11, 2011

(In [[r:0745393f9828f571a2ddb147325ceab6aa4950d8]]) Improve custom serializers to enable interception of collections (fixes #1079)

Branch: master

jonifreeman was assigned Mar 1, 2012

@etorreborre etorreborre pushed a commit to etorreborre/framework that referenced this issue Dec 3, 2014

Joni Freeman Improve custom serializers to enable interception of collections (fixes 0745393

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment