Giter Site home page Giter Site logo

Comments (8)

pjfanning avatar pjfanning commented on September 23, 2024

what happens if you remove .enable(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)?

from jackson-module-scala.

impasse avatar impasse commented on September 23, 2024

The result is still the same, List[Map].

from jackson-module-scala.

pjfanning avatar pjfanning commented on September 23, 2024

I see you are using Int - and type erasure makes that very hard to support.

Please read https://github.com/FasterXML/jackson-module-scala/wiki/FAQ#deserializing-optionint-seqint-and-other-primitive-challenges

from jackson-module-scala.

impasse avatar impasse commented on September 23, 2024
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

@main
def test(): Unit = {
  val mapper: JsonMapper = JsonMapper.builder()
    .addModule(DefaultScalaModule)
    .build()
  
  case class I(i: Option[Int])
  case class W(b: List[I])
  val d = mapper.readValue[W](
    """
      |{ "b": [ { "i": 1 }, { "i": 2 } ] }
      |""".stripMargin, classOf[W])
  println(d.b.head.i)
}

But when I replaced it with Option[Int], it's still the same List[Map]:
class scala.collection.immutable.Map$Map1 cannot be cast to class test$package$I$1

from jackson-module-scala.

impasse avatar impasse commented on September 23, 2024
package com.mokahr.tntsync

import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule

@main
def test(): Unit = {
  val mapper: JsonMapper = JsonMapper.builder()
    .addModule(DefaultScalaModule)
    .build()

  case class I(i: Option[Int])
  case class W(b: Array[I])
  val d = mapper.readValue[W](
    """
      |{ "b": [ { "i": 1 }, { "i": 2 } ] }
      |""".stripMargin, classOf[W])
  println(d.b.head.i)
}

But when I replaced List[I] with Array[I], it was able to print Some(1) normally.

from jackson-module-scala.

pjfanning avatar pjfanning commented on September 23, 2024

There are lots of solutions in that FAQ, could you try some of them? I'm afraid that I don't have time to debug this right now.

There are a lot of other Scala libs to process JSON. This one is constrained by the fact that it uses Java reflection. If you don't like the workarounds in the FAQ, you could try another lib.

from jackson-module-scala.

impasse avatar impasse commented on September 23, 2024

Okay, I'm just giving feedback on this issue. It doesn't affect my usage at the moment.

from jackson-module-scala.

pjfanning avatar pjfanning commented on September 23, 2024

I added 6441dd9 and the test seems to work ok - maybe I'm missing something

from jackson-module-scala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.