Towards a JSON API for the JDK
Brian Goetz
brian.goetz at oracle.com
Fri May 16 17:46:09 UTC 2025
If you read the implementation, you'll see that significant laziness is
indeed possible for JsonObject and JsonArray, even while doing eager
validation. (Of course, one can shift the balance to achieve various
other tradeoffs.)
On 5/16/2025 10:35 AM, forax at univ-mlv.fr wrote:
> ----- Original Message -----
>> From: "Brian Goetz"<brian.goetz at oracle.com>
>> To: "Remi Forax"<forax at univ-mlv.fr>, "Paul Sandoz"<paul.sandoz at oracle.com>
>> Cc: "core-libs-dev"<core-libs-dev at openjdk.org>
>> Sent: Friday, May 16, 2025 2:53:18 PM
>> Subject: Re: Towards a JSON API for the JDK
>> On 5/15/2025 5:27 PM, Remi Forax wrote:
>>> It's not clear to me why JsonArray (for example) has to be an interface instead
>>> of a record ?
>> Oh, you know the answer to this. A record limits us to a single
>> implementation with a rigid representation. Behind an interface, we can
>> hide lazy parsing and inflation, wrapping other representations to
>> reduce copies, etc.
> First, let me refine the question.
> There are only 4 kinds of JSON values that benefit from having different representations, object, array, string and number.
> For object and array, both takes an interface as parameter (Map or List) so JsonArray and JSonObject do not need to be themselves interfaces.
>
> So the only values where it may be worth to be modeled using an interface are JsonString and JsonNumber, because as you said, you can do "lazy" parsing.
>
> But delaying the parsing of the content has the side effect that even if Json.parse() did not throw an exception, it does not mean that the JSON text is valid, an exception may be thrown later.
>
> Now, for me, this library is more about being simple and safe than fast.
> If you agree with that, delaying the parsing is not a good idea, thus JSON values should be modeled using records and not interfaces.
>
> regards,
> Rémi
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250516/b6662a49/attachment-0001.htm>
More information about the core-libs-dev
mailing list