adding jsonb to core project has killed all slingServlets.

Avatar

Avatar

TB3dock

Avatar

TB3dock

TB3dock

06-04-2021

In order to convert between json and objects in an Adobe AEM project, I added the following to the core modules pom.xml file:

<dependency>
  <groupId>javax.json.bind</groupId>
  <artifactId>javax.json.bind-api</artifactId>
  <version>1.0</version>
</dependency>

<dependency>
  <groupId>org.eclipse</groupId>
  <artifactId>yasson</artifactId>
  <version>1.0</version>
  <scope>runtime</scope>
</dependency>

I added them right below this dependency:

 

<artifactId>slf4j-test</artifactId>

 

If I then add the following line:

    Jsonb jsonb = JsonbBuilder.create();

to any sling servlet (and the import), it complies without error, but when I try to hit any servlet I get the below error.  If I remove the line, it works again.  Could it be I have added the dependency to the wrong pom.xml, or in the wrong place, or need to add it somewhere else also?

Resource at '/bin/demo/querybuilder' not found: No resource found
Cannot serve request to /bin/demo/querybuilder in BundledScriptServlet (/libs/sling/servlet/errorhandler/404.jsp)

Request Progress:
      0 TIMER_START{Request Processing}
     21 COMMENT timer_end format is {<elapsed microseconds>,<timer name>} <optional message>
     43 LOG Method=GET, PathInfo=null
     58 TIMER_START{handleSecurity}
   3285 TIMER_END{3224,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@bd75a69 returns true
   4676 TIMER_START{ResourceResolution}
   5588 TIMER_END{910,ResourceResolution} URI=/bin/demo/querybuilder resolves to Resource=NonExistingResource, path=/bin/demo/querybuilder
   5601 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/demo/querybuilder', selectorString='null', extension='null', suffix='null'
   5601 TIMER_START{ServletResolution}
   5615 TIMER_START{resolveServlet(/bin/demo/querybuilder)}


 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

asutosh_j3

Avatar

asutosh_j3

asutosh_j3

06-04-2021

Hi @TB3dock 

To convert JSON to Java or Java to JSON you can use the inbuilt library i.e. Gson. It's simple and easy to use.

Add the following dependency on POM:

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>

You can create some util method and use it wherever it is required.

public static Object getObjectFromJson(String jsonString, Object obj) {
Gson gson = new Gson();
Object returnValue = null;
try {
returnValue = gson.fromJson(jsonString, obj.getClass());
} catch (Exception e) {
log.error("Exception occured in Something :: getObjectFromJson --> ", e);
}
return returnValue;
}
public static String getJsonFromObject(Object obj) {
Gson gson = new Gson();
String returnValue = null;
try {
returnValue = gson.toJson(obj);
} catch (Exception e) {
log.error("Exception occured in Something :: getJsonFromObject --> ", e);
}
return returnValue;

}

Please use the below article.

 

https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/co....

 

https://www.aemtutorial.info/2019/05/how-to-fix-json-deprecated-api-error-in.html

 

Hope this helps!

Thanks!

Answers (1)

Answers (1)

Avatar

Avatar

KiranVedantam1992

Avatar

KiranVedantam1992

KiranVedantam1992

06-04-2021

Hi @TB3dock,

 

First, check if the bundle is active. If not try changing the scope to provided. If that did not help, try adding the bundle in the Embedded section.

 

To know how to add it in the embedded section, check my post here.

 

If nothing works, please share the log.

 

Hope this helps.

 

Thanks,

Kiran Vedantam