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

com.codahale.jerkson.deser.EitherDeserializer.scala Maven / Gradle / Ivy

There is a newer version: 0.6.3
Show newest version
package com.codahale.jerkson.deser

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.node.TreeTraversingParser
import com.fasterxml.jackson.databind._

class EitherDeserializer(config: DeserializationConfig,
                         javaType: JavaType) extends JsonDeserializer[Object] {
  def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
    val node = jp.readValueAsTree[JsonNode]
    val tp = new TreeTraversingParser(node, jp.getCodec)

    try {
      Left(tp.getCodec.readValue[Object](tp, javaType.containedType(0)))
    } catch {
      case _: Throwable => Right(tp.getCodec.readValue[Object](tp, javaType.containedType(1)))
    }
  }

  override def isCachable = true
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy