jakartaee / jakartaee/jsonp-api

JsonParser should provide access to underlying UTF8 stream

Open
#258 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
160
Forks
64
Avg merge
4d 5h
Merged PRs (30d)
4

Description

This is an enhancement idea for the next version of JSON-P.

UTF-8 is the predominant representation for JSON text:
From https://tools.ietf.org/html/rfc8259:

> JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8

Currently JsonParser only exposes JSON strings as java.lang.String (see JsonParser#getString())

This conversion between UTF8 and java.lang.String is typically expensive in terms of processing and memory. And some consumers may be converting the JSON to other formats (e.g. a storage format for a database) in which case the java.lang.String value is immediately re-serialized anyway.

javax.xml.stream.XMLStreamReader provides methods like getTextLength() and getTextCharacters() that allow the consumer to avoid String materialization.

I think JsonParser could have similar methods that expose the underlying UTF-8 value. One option would be something like XMLStreamReader:

int getUTF8Length()
getUTF8(int sourceStart, byte[] target, int targetStart, int length);

Another option would be something like:

getString(OutputStream out)

Which writes the current VALUE_STRING event as UTF-8.

Contributor guide

Open the contributing guide

Research direction

Start with JsonParser#getString() and compare the proposed access patterns with XMLStreamReader methods such as getTextLength() and getTextCharacters(). The issue does not identify files or tests, and the API shape is unresolved; done would require agreeing on and specifying a supported way to access VALUE_STRING content as UTF-8 without String materialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.