Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

100% Positive

Analyzed from 613 words in the discussion.

Trending Topics

#json#library#java#why#jackson#jep#serialization#need#api#jsonobject

Discussion (14 Comments)Read Original on HackerNews

dfabulich25 minutes ago
A stated goal of the API is to have "low ceremony"; this seems like a lot of ceremony.

    IO.println(JsonObject.of(Map.of("providers",
        JsonArray.of(List.of(JsonString.of("SUN"),
            JsonString.of("SunRsaSign"),
            JsonString.of("SunEC"))))));
There's gotta be a better way!

Surely there could be some way of creating a JsonArray of native Java Strings, Booleans, Doubles, and Integers without requiring clients to explicitly convert each value into a JsonValue. And why am I forced to convert a native List into a JsonArray just so I can make it the value of a JsonObject?

Why can't I write this?

   JsonObject.of(Map.of("providers", List.of("SUN", "SunRsaSign", SunEC"))));
whaley41 minutes ago
Meanwhile, Jackson has been going strong for almost 20 years now https://github.com/FasterXML/jackson.

One of my favorite things about Jackson was being able to arbitrarily navigate through the document with a rich and fluent API (JsonNode) in jackson.databind, which this JEP at least conceptually borrows from with the JsonValue abstraction. Both of these are better than how some of the other implementations do it, where you are effectively working with glorified Map<String,Object>

whartungabout 1 hour ago
Well, this will be fun.

I already have one of these (I'm sure I'm not alone). It's about 500 lines.

I found I'm not a huge fan of the JAX-B-ish style serialization of Java objects for JSON. I don't want to really downplay them, they certainly have their uses, they're very popular, I just don't like fighting them. Hand writing JSON marshaling code has not been arduous for me (notably with my utility layer). (I also, philosophically, strive to avoid "magic" in my code as much as practical.)

Of course, I still need a parser, I'm using GSONs parser, which means I'm still dragging in the whole bean level serialization infrastructure. I just don't use it. And while I've done JSON parsers before, I felt it was something better to import than maintain myself. So, in that sense, it's a mixed bag.

But, I do enjoy using it.

This will be a worthwhile JDK capability. Ideally it can replace mine.

gavinrayabout 1 hour ago
It used to be the case that if you wanted to build a web service on the JVM, you wanted 2 things:

1. An HTTP server library/framework

2. A JSON library

We got a decently-performing and unopionated HTTP server in JDK 18 with "HttpHandlers" and "SimpleFileServer" plus "jwebserver" CLI

It later received Virtual Thread support, which made performance + scalability very competitive.

With a JSON module, you finally won't NEED to rely on external deps to build a basic JVM web service without pain.

Now, we just need a proper CLI framework like picocli, or at least "argparse" from Python stdlib...

Sankozi26 minutes ago
Using JSON as a configuration format is a big mistake. JEP authors could learn a bit from package.json problems. Hope JSON will not be used in anything significant for JDK configuration.
IanGabes44 minutes ago
Including this in the standard library speaks to how much a citizen JSON has become, where a language simply can't afford to not consider it.

I find it interesting to note that nowhere in this JEP is the word "serialization", which is what most people might associate with JSON libs. Or rather, they are studiously ignoring that feature and just improving the ergonomics of interacting with JSON.

ameliaquining32 minutes ago
If I'm guessing correctly what you mean by "serialization", the JEP refers to it as "data binding" and includes a section on why it's not going to be part of this library.
mcfedr31 minutes ago
its crazy its taken Java so long to realise this
MeteorMarc43 minutes ago
Many languages have json marshalling and unmarshalling in their standard libs, e.g. C#, golang, python.
deepsun16 minutes ago
You forgot Javascript :)
delusional6 minutes ago
They're doing a real API instead of the magic annotation hell that JavaEE fans love. Thank god. I welcome this, because Java has a lot of need for a good, common, performant, and well maintained JSON library that doesn't come along with the complexity of being JSON-B.
exabrial33 minutes ago
Is this just including JSR-367 in the sdk? I've used that for years along with its many implementations. Great stuff!
q3k33 minutes ago
Happy to see that numbers are arbitrary width/precision until explicitly cast by the user. This goes against so many other JSON libraries that will always cast all numbers to double (or even float) thereby silently corrupting JSON numbers representing large values (eg. memory addresses).

Does anyone know how this behaves when encountering a repeated key in an object? (RFC8259 states that keys SHOULD be unique, which makes that generally allowed and implementations all behave slightly differently).

lmz7 minutes ago
Not sure why they didn't include the BigDecimal conversion directly on the JsonNumber object instead of going through the String representation.

Duplicate keys are a parse exception.

> Additionally, documents must not have objects with duplicate member names.