jsonb-api
jsonb-api copied to clipboard
Add jsonb.close() to all code examples in documentation
Docs show using jsonb.fromJson() and jsonb.toJson() following Jsonb jsonb = JsonbBuilder.create(), but the docs are highly misleading in not showing the required jsonb.close() calls.
Update the docs to show the use of jsonb.close() or try-with-resources in all examples where a Jsonb instance is retrieved.
JSON-B implementations can memory-leak if close() is never called.
Johnzon is confirmed to leak if a local-scope Jsonb instance is never closed in a frequently used method (for example, in a MicroProfile Health implementation).
In that vein, can we have a better exception for close than Exception?
From AutoCloseable.java:
/*
* @apiNote
* While this interface method is declared to throw {@code
* Exception}, implementers are <em>strongly</em> encouraged to
* declare concrete implementations of the {@code close} method to
* throw more specific exceptions, or to throw no exception at all
* if the close operation cannot fail.
*/
Handling Exception is very unsightly
try (Jsonb jsonb = JsonbBuilder.create()) {
return jsonb.fromJson(....);
} catch (Exception e) {
throw new RuntimeException(e);
}