jsonp-api icon indicating copy to clipboard operation
jsonp-api copied to clipboard

Methods in Json re-create JsonProvider on each execution, Json should cache the result of JsonProvider.provider()

Open rbygrave opened this issue 2 years ago • 2 comments

The methods in Json use JsonProvider.provider() and this re-creates the JsonProvider on each execution.

The javadoc for JsonProvider.provider() suggests that the caller should cache the resulting JsonProvider and jakarta.json.Json does not do this, so I think this is a bug.

For example, in Json we see:

    /**
     * ...
     */
    public static JsonParser createParser(Reader reader) {
        return JsonProvider.provider().createParser(reader);
    }

    /**
     * ...
     */
    public static JsonParser createParser(InputStream in) {
        return JsonProvider.provider().createParser(in);
    }

In the javadoc for JsonProvider.provider() is says:

"Creates a JSON provider object. ... Users are recommended to cache the result of this method."

I believe that means that Json should be changed to indeed cache the result of JsonProvider.provider().

rbygrave avatar Dec 14 '21 21:12 rbygrave