Comments (3)
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.
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.
That makes sense -- thanks. Your work on Spray is much appreciated.
from spray-json.
Related Issues (20)
- Publish for Scala 2.13.0 HOT 3
- Provide implicits automatically without extra imports HOT 1
- Provide jsonFormatN method overloads HOT 4
- JsonParserSpecJvm is failing HOT 3
- Documentation review and migration guide for 1.5.0 release
- How to debug "Cannot find JsonWriter or JsonFormatter type class" errors
- Not able to parse the Json file with its relation_tree and split into multiple Json file for each child without any hard coding of Node/Tag (As structure of Json is not always same also very lengthy json). Input and Output is pasted below :
- Publish 1.3.6 release (including Scala.js) HOT 1
- Scaladoc
- DefaultJsonProtocol.viaSeq looses ordering for ordered iterables HOT 10
- Is JsonParser thread safe?
- Default JsonWriter for collections
- recursive Json Does not seem to work as documented HOT 3
- What are your plans for spray-json regarding Scala 3? HOT 4
- Generated jsonFormatN has unexpectedly large sizeHint HOT 1
- Cross-compile for scala 3? HOT 1
- Introduce an optional Scala 3 macro module, with full pickling support.
- Is this project still maintained? HOT 2
- No implicit arguments of type: JsonReader[Double] HOT 1
- Cannot parse as Long from String format field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spray-json.