GithubHelp home page GithubHelp logo

Comments (3)

NicholasSterling avatar NicholasSterling commented on July 18, 2024

Same question for toJson:

scala> List(1,"two").toJson
:14: error: Cannot find JsonWriter or JsonFormat type class for List[Any]
List(1,"two").toJson

Why wouldn't that return the same AST I get from this parse?

scala> JsonParser( """[1,"two"]""" )
res22: cc.spray.json.JsValue = [1,"two"]

from spray-json.

sirthias avatar sirthias commented on July 18, 2024

Nicholas,
spray-json is completely statically typed, there is no reflection or dynamic inspection of JSON content to figure out some typing on runtime. This means that you cannot convert a List[Any] to JSON (or vice versa), since spray-json does not know how to convert Any to JSON (and vice versa). Any is simply too general. What you are asking for requires dynamic behavior and comes with the respective drawbacks. For example, if you have a List[Any] containing not only Int and String objects but also an object of a custom type Person and you have not defined a JsonFormat[Person] the compiler would not be able to figure out at compile time that something is wrong.
With spray-json this cannot happen.
If it compiles then all the ingredients for successful JSON reading/writing are there...

HTH and cheers,
Mathias

PS: Please use the mailing list for such questions in the future!

from spray-json.

NicholasSterling avatar NicholasSterling commented on July 18, 2024

That makes sense -- thanks. Your work on Spray is much appreciated.

from spray-json.

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.