Skip to content

Commit

Permalink
use static object mapper instances
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Dec 15, 2023
1 parent eedc11f commit 3aed414
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
public final class DefaultMediaFormatListProvider extends SlingSafeMethodsServlet {
private static final long serialVersionUID = 1L;

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Override
protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException {
// get list of media formats for current medialib path
Expand Down Expand Up @@ -86,7 +88,7 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt

// serialize to JSON using Jackson
response.setContentType(ContentType.JSON);
response.getWriter().write(new ObjectMapper().writeValueAsString(mediaFormatList));
response.getWriter().write(OBJECT_MAPPER.writeValueAsString(mediaFormatList));
}

protected Set<MediaFormat> getMediaFormats(SlingHttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public final class MediaFormatValidateServlet extends SlingSafeMethodsServlet {
static final String RP_MEDIA_CROPAUTO = "mediaCropAuto";
static final String RP_MEDIA_REF = "mediaRef";

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

/**
* Prefix for i18n keys to generated messages for media invalid reasons.
*/
Expand Down Expand Up @@ -120,7 +122,7 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt
result.reasonTitle = getI18nText(i18n, ASSET_INVALID_I18N_KEY);
}
response.setContentType(ContentType.JSON);
response.getWriter().write(new ObjectMapper().writeValueAsString(result));
response.getWriter().write(OBJECT_MAPPER.writeValueAsString(result));
}

private String getMediaInvalidReasonI18nKeyOrMessage(@NotNull Media media) {
Expand Down

0 comments on commit 3aed414

Please sign in to comment.