3 ms·
yah they should've done something like: send(JSONSerialization.with(StringSerializer.class, DateTimeSerializer.class).serialize(JSONObjectFactory.put(PairF
by the1 13y ago
yah they should've done something like:
send(JSONSerialization.with(StringSerializer.class, DateTimeSerializer.class).serialize(JSONObjectFactory.put(PairFactory.of(String.class, String.class).getInstance("author", "system"), PairFactory.of(String.class, String.class).getInstance("message", "Only json is allowed"), PairFactory.of(String.class, DateTime.class).getInstance("time", new Date())).getInstance()))
no, it's just json4s dsl for constructing json. If you wanted, you could've used constructors yourself:
send(pretty(render(JObject(List(JField("author", JString("system")), JField("message", JString("Only json allowed")), JField("time", JString(new DateTime().getTime().toString()))))
usually scala libraries come with an easy to read/write DSL version of the API along with a more verbose java-style API shown above. Many libraries don't document with a plenty of examples. But, it really takes 10 minutes to learn DSL version in many cases. And, it gives you wings. There are plenty of benefits of DSL. You can research online about them.
- k__ 13y agoI hate the Java style as much as this nonsense-operator-like-function-name style of Scala. Why do they have to name them ~ % %%, if they can name them ANYTHING. Just to make the writing shorter? It's like using variable names like a, b, c, data, value etc. I want readable code, not short code by hook or by crook...
- the1 13y agooperators like +, -, /, %, ^, ... read much better once you learn their meanings and how to use them. it's okay to learn things.