Coder Social home page Coder Social logo

Comments (4)

ghik avatar ghik commented on July 17, 2024

Hello, thanks for the report.
The problem is in this line: https://github.com/plokhotnyuk/jsoniter-scala/blob/3f81687acabc30202d43c2a9f31fb541fb342112/benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/AVSystemCodecs.scala#L48

implicit val twitterAPIGenCodec: GenCodec[Seq[Tweet]] = GenCodec.materializeRecursively[Seq[Tweet]]

You should not macro-materialize codec for a Seq, because GenCodec[Seq[A]] is automatically provided as long as there is a GenCodec[A], so this would be sufficient:

implicit val twitterAPIGenCodec: GenCodec[Tweet] = GenCodec.materializeRecursively[Tweet]

... but I just realized that it doesn't work because GenCodec cannot be materialized for case classes with more than 22 fields 😢
Also, the macro itself should be more secured to reject materializing something like a Seq.
Will fix that.

from scala-commons.

ghik avatar ghik commented on July 17, 2024

This is interesting. It turns out that Seq[A] is actually a completely valid type for macro materialization of GenCodec because it has a companion object with matching apply and unapplySeq methods. The only problem is that the argument of apply is also a Seq[A] which creates a cycle and causes stack to overflow.

from scala-commons.

plokhotnyuk avatar plokhotnyuk commented on July 17, 2024

Stack overflow cannot be reproduced by this code with v1.28.2, but JsonStringInput.read[Seq[Tweet]] returns an instance of Vector instead of expected List:
https://github.com/plokhotnyuk/jsoniter-scala/blob/7aa20826271d03262b734caa40d818bda5f725d3/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/TwitterAPIBenchmark.scala#L25-L28

Should I close this issue and open a new one for that case?

from scala-commons.

ghik avatar ghik commented on July 17, 2024

@plokhotnyuk I've created separate issue for that, closing this one. Thanks!

from scala-commons.

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.