Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default protocol support for Seq[Any] and Map[String, Any] #36

Open
velvia opened this issue Dec 21, 2012 · 2 comments
Open

Add default protocol support for Seq[Any] and Map[String, Any] #36

velvia opened this issue Dec 21, 2012 · 2 comments

Comments

@velvia
Copy link

velvia commented Dec 21, 2012

Right now there is no protocol that can convert to/from Seq[Any] and Map[String, Any]. This prevents spray-json from being used in many scenarios, unless you code up your own protocol. Spray-json should provide out of the box protocols for these common generics.

I have code that I would like to contribute back for these protocols.

@jrudolph
Copy link
Member

Isn't the only thing you would need to provide is a JsonFormat[Any] to support both of the other ones? The reason there is no such format accessible by default is that effectively you turn off type-safety with such a format. Apart from that it is hard (or even generally impossible) to provide because Any is unbounded and you can never know which types a user of the library would use the format with in front. So, as it stands this is a 'won't fix'.

I guess you have a more concrete usecase in mind than the fully general case where we or you could provide a solution?

@velvia
Copy link
Author

velvia commented Jan 1, 2013

I'm not asking for supporting the open ended case, just all the standard JSON types. The use case is for general JSON-based events, so the fields can be strings, numbers, bools, floats/doubles. The format can change so just using case classes isn't a good fit, and type safety doesn't matter anyways as the field values of the events themselves are opaque to my app.

Generic map/list support (with the types mentioned above) is already implemented by most other JSON libraries -- definitely in JSON4S, as well as Jacks. I honestly have considered switching to the other libraries because out of the box usability is much better for my use case.

I already have working code, not quite sure how to attach it. I simply use a pattern match for the type comparison, although I can use something more efficient (lookup table possibly...)

@jrudolph jrudolph added this to the Next major release milestone Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants