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

com.twitter.finatra.json.internal.caseclass.jackson.FinatraCaseClassDeserializers.scala Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package com.twitter.finatra.json.internal.caseclass.jackson

import com.fasterxml.jackson.databind.deser.Deserializers
import com.fasterxml.jackson.databind.{BeanDescription, DeserializationConfig, JavaType}

class FinatraCaseClassDeserializers extends Deserializers.Base {
  val PRODUCT = classOf[Product]
  val OPTION = classOf[Option[_]]
  val LIST = classOf[List[_]]

  override def findBeanDeserializer(javaType: JavaType, config: DeserializationConfig, beanDesc: BeanDescription) = {
    if (maybeIsCaseClass(javaType.getRawClass))
      new FinatraCaseClassDeserializer(javaType, config, beanDesc)
    else
      null
  }

  private def maybeIsCaseClass(cls: Class[_]): Boolean = {
    if (!PRODUCT.isAssignableFrom(cls)) false
    else if (OPTION.isAssignableFrom(cls)) false
    else if (LIST.isAssignableFrom(cls)) false
    else if (cls.getName.startsWith("scala.Tuple")) false
    else true
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy