Skip to content

Commit

Permalink
[RESTEASY-1923] JsonWriterFactory and JsonReaderFactory re-created pe…
Browse files Browse the repository at this point in the history
…r request

WriterFactory and ReaderFactory are created with a null configuration, so they are targets for caching and should reduce the cpu utilization for each request and response.
  • Loading branch information
johnaohara authored and asoldano committed Jun 8, 2018
1 parent d2c6961 commit 19dcccb
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -21,6 +21,9 @@ public class AbstractJsonpProvider
@Context
javax.ws.rs.ext.Providers providers;

private static final JsonReaderFactory readerFactory = Json.createReaderFactory(null);
private static final JsonWriterFactory writerFactory = Json.createWriterFactory(null);

public static Charset getCharset(final MediaType mediaType)
{
if (mediaType != null)
Expand All @@ -41,7 +44,7 @@ protected JsonReader findReader(MediaType mediaType, InputStream is)
}
if (factory == null)
{
factory = Json.createReaderFactory(null);
factory = readerFactory;
}
Charset charset = getCharset(mediaType);
return charset == null ? factory.createReader(is) : factory.createReader(is, charset);
Expand All @@ -57,7 +60,7 @@ protected JsonWriter findWriter(MediaType mediaType, OutputStream os)
}
if (factory == null)
{
factory = Json.createWriterFactory(null);
factory = writerFactory;
}
Charset charset = getCharset(mediaType);
return charset == null ? factory.createWriter(os) : factory.createWriter(os, charset);
Expand Down

0 comments on commit 19dcccb

Please sign in to comment.