'Scala Jackson deserialization failing with "non-static inner classes" error version Jackson2.10

I am trying to upgrade from Jackson-2.5 to 2.10

Below deserialization code was working for me, before but post upgrade the solution is failing with following error:

[ Cannot construct instance of `$line11.$read$$iw$$iw$RegularMetric$1` (although at least one Creator exists): non-static inner classes like this can only by instantiated using default, no-argument constructor
 at [Source: (String)".... (through reference chain: com.fasterxml.jackson.module.scala.deser.GenericFactoryDeserializerResolver$BuilderWrapper[0]) ]

metricsJson is a valid Json which was working fine before.

Adding code snippet for reference.

import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper


case class ThresholdExpression(@JsonProperty("term") term: String,
                               @JsonProperty("comparisonOperator") comparisonOperator: String,
                               @JsonProperty("thresholdValue") thresholdValue: String,
                               @JsonProperty("prorated") prorated: Boolean
                              ){

  def getThreshold(proratedFactor : Double = 1): String = {
    ..
    ..
  }
}

case class RegularMetric(@JsonProperty("name") name: String,
                         @JsonProperty("premiumPlusThreshold") premiumPlusThreshold: List[ThresholdExpression],
                         @JsonProperty("premiumThreshold") premiumThreshold: List[ThresholdExpression],
                         @JsonProperty("standardThreshold") standardThreshold: List[ThresholdExpression]){
  def getMetricTierColumnName() : String = {
    s"${name}Metric"
  }

  def getMetricRateColumnName() : String = {
    s"${name}"
  }
}



object Classification {

  private def getRegularMetrics(metricsConfigJson: String): List[RegularMetric] = {
    JsonUtils.fromJson[List[RegularMetric]](metricsJson)
  }

  object JsonUtils {

    def fromJson[T](json: String)(implicit m : Manifest[T]): T = {
      val mapper = new ObjectMapper() with ScalaObjectMapper
      mapper.registerModule(DefaultScalaModule)
      mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
      mapper.readValue[T](json)
    }
  }

}

On deep dive I found that with Jackson-databind 2.10 there are some tight type check implemented because of which my complex object, which consists of lists is not being deserialized, but the error is a bit misleading and I am not able to figure what am I doing wrong here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source