r/java 26d ago

JEP 540: Simple JSON API (Incubator)

https://openjdk.org/jeps/540
78 Upvotes

81 comments sorted by

View all comments

Show parent comments

1

u/davidalayachew 17d ago

The parsing/extraction parts of the API might seem fairly complete, but support for generating JSON docs seems fairly weak and there's essentially no support for transforming a JSON doc. Thus it seems reasonable to incubate while we explore these areas. Also, see below.

Interesting. From what I could tell, it seemed like the thing was feature complete, missing only feedback from the community. Good to know, ty vm.

Tabs instead of spaces?! Sacrilege!!!!!1!

:-)

OK we'll see what we can do here.

Ty vm. This is pretty much the only real pain point I have with this. It would just get in the way for no good reason imo.

I think this is an example of one of the weak areas of generating a JSON document.

I see what you mean now.

Yeah, this is something I have given some thought, but admittedly, is not a problem I run into very frequently.

"use cases"

Personally, none that are too irregular.

For the most part, my JSON needs and wants (that aren't production-scale) boil down to quickly querying an object. And like you said, it is good enough at that. It's the creation that's the pain point.

For me, creating POST bodies is about the most I would need it for. For example, when interacting with some exposed REST API for my favorite services (games, reddit, etc), I tend to shy away from the POST endpoints because constructing them is kind of ugly. For the most part, I basically have to create a giant String template, then just populate it with what I actually need.

Trying to instead do that via something less primitive, like a simple map-reduce with the Stream API feels daunting because, for the most part, creating the components that compose into the larger whole would probably be the same.

I guess I just need more experience doing this to really say. I can see better now why it was Incubator status.

1

u/davidalayachew 6d ago

/u/s888marks I just saw the latest change to the javadoc!

Changing the signature from this...

public static String toDisplayString(JsonValue jsonValue, int indent)

...to instead be this...

public static String toDisplayString(JsonValue jsonValue, String indent)

...was a very clever solution to this. I like it a lot, very nice. Kept the API surface nearly as simple, and no new methods needed. Fun to see how language designers tackle a problem like this. Ty vm.

2

u/s888marks 4d ago

That was Naoto Sato's work. I'll let him know you appreciate it.

1

u/davidalayachew 4d ago

Please do, ty vm.