Skip to content

Commit

Permalink
Eliminate usage of org.apache.sling.commons.json (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert authored Dec 15, 2023
1 parent 9d24655 commit c433e44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.7.2" date="not released">
<action type="update" dev="sseifert" issue="1">
Eliminate usage of org.apache.sling.commons.json
</action>
</release>

<release version="1.7.0" date="2023-02-24">
<action type="update" dev="sseifert">
Switch to Java 11 as minimum version.
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.adobe.aem</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package io.wcm.wcm.parsys.componentinfo.impl;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;

Expand All @@ -41,6 +43,7 @@

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.wcm.sling.commons.adapter.AdaptTo;
import io.wcm.sling.commons.request.RequestParam;
Expand Down Expand Up @@ -68,6 +71,8 @@ public final class ParsysComponentsServlet extends SlingSafeMethodsServlet {

private static final Logger log = LoggerFactory.getLogger(ParsysComponentsServlet.class);

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Reference
private AllowedComponentsProvider allowedComponentsProvider;

Expand All @@ -82,7 +87,7 @@ protected void activate() {
enabled = instanceTypeService.isAuthor();
}

@SuppressWarnings({ "null", "deprecation" })
@SuppressWarnings("null")
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
if (!enabled) {
Expand All @@ -106,7 +111,7 @@ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse r

response.setContentType(ContentType.JSON);

org.apache.sling.commons.json.JSONArray allowedComponents = new org.apache.sling.commons.json.JSONArray();
Collection<String> allowedComponents = Collections.emptyList();

String relativePath = RequestParam.get(request, RP_PATH);
String resourceType = RequestParam.get(request, RP_RESOURCE_TYPE);
Expand All @@ -120,10 +125,10 @@ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse r
allowedComponentsRelative.add(ResourceType.makeAbsolute(allowedResourceType, resolver));
}

allowedComponents = new org.apache.sling.commons.json.JSONArray(allowedComponentsRelative);
allowedComponents = allowedComponentsRelative;
}

response.getWriter().write(allowedComponents.toString());
response.getWriter().write(OBJECT_MAPPER.writeValueAsString(allowedComponents));

// output profiling info in DEBUG mode
if (log.isDebugEnabled()) {
Expand Down

0 comments on commit c433e44

Please sign in to comment.