spray-json icon indicating copy to clipboard operation
spray-json copied to clipboard

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

Open velvia opened this issue 11 years ago • 2 comments

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.

velvia avatar Dec 21 '12 18:12 velvia

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?

jrudolph avatar Dec 31 '12 13:12 jrudolph

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...)

velvia avatar Jan 01 '13 01:01 velvia