Open kostrse opened 6 years ago
Is this by design always assumed that that users should implement full JsonFormat rather than only JsonReader (or only JsonWriter)?
Yes, right now, it is like that. The reason is that the way the implicits are structured don't allow for an easy split up of specific JsonReader
and JsonWriter
so that JsonFormat
is still working (at least that's how I remember it from some years ago). Changing the implicit setup right now is currently too dangerous because of compatibility constraints.
Is any change planned for this? If it's too dangerous right now then it always will be, I suppose? This behaviour is quite misleading and it makes JsonReader
s relatively useless except in very simple cases, and requires having write implementations where they're not required at all, or else working around it by adding additional "standard" readers yourself. It's not the easiest thing to debug, either, as it can take a while to get from the compile error "Cannot find JsonReader or JsonFormat type class for List[T]" to figuring out that you really do have a JsonReader[T] in scope and the problem is a missing generic ListReader, which you have to dive into the library code to discover. I don't think I've seen anything warning about this aspect of the API, though granted I don't see anything especially obvious in your main docs encouraging using JsonReader
. If it's unlikely to change it's probably worth making it very clear that JsonReader
isn't really intended to be used.
spray-json has JsonFormat for a List[T] but doesn't have JsonReader.
https://github.com/spray/spray-json/blob/326a001a44bd818750f2baa3f65e68184f5a2d5a/src/main/scala/spray/json/CollectionFormats.scala#L22-L31
I'm writing a domain model and most of my entities have only JsonReaders defined.
I don't need to serialize to JSON (only parse) so I decided to not implement JsonWriters/JsonFormat.
Is this by design always assumed that that users should implement full JsonFormat rather than only JsonReader (or only JsonWriter)?
In some cases serialization expected to be used only in one way or another, so implementing JsonFormat may be unnecessary sometimes.
SO: https://stackoverflow.com/q/51331765/191683