4 ms·
I've written enough Clojure over the years to think that this is probably not the case. The reason this problem doesn't happen as much with Clojure is that the
by astine 6y ago
I've written enough Clojure over the years to think that this is probably not the case. The reason this problem doesn't happen as much with Clojure is that the Clojure data structure is closer to JSON (and when using EDN instead of JSON, is identical.) If your serialization object model is close to your in-code object model, translating between the two is easy. If your serialization object model is distant from your in-code object model, then translation becomes difficult.
You can directly serialize and deserialize plain old Java objects to and from a native format and it's trivial to do so, but serializing to and from JSON is trickier because JSON is meant to represent dynamically typed data stored in maps and lists, but Java doesn't naturally store data in that manner. Java's manner is more obtuse, but if you could be certain that both the producer and the consumer of an object was going to be Java, creating a serialization format that could be transparently used would be a straightforward task. That is, so long as both the source and target of your serialization are in the same language, the problem is a lot simpler, and if your language happens to be closer Javascript (the source of JSON) it's also relatively simpler to write a JSON parser for it.
- vemv 6y agoI see more similitudes than differences in our thinkings :) One can make the problem easier in Java by using HashMaps instead of classes, just like one could make it harder in JavaScript by emulating rigid OOP. Which is to say, practically all languages have all the necessary technology for JSON not to be a pervasive problem. The only impediments are social/ideological. (An idea which resonates with the original article's message)
- mrkeen 6y agoYou might expect your service to only receive a particular JSON format, but it could really receive any JSON, or any String, or any bytes, etc. At some point in the program you want to rely on your data already having been validated. HashMaps are not a good fit for this. For me the neatest way to address both of these is to have a very narrow conversion window. Transform the data from bytes/string/hashmaps into well-typed objects only within the controller.