Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

adding jsonb to core project has killed all slingServlets.

Avatar

Avatar
Ignite 10
Level 4
TB3dock
Level 4

Likes

34 likes

Total Posts

203 posts

Correct Reply

4 solutions
Top badges earned
Ignite 10
Boost 25
Give Back 25
Validate 10
Validate 1
View profile

Avatar
Ignite 10
Level 4
TB3dock
Level 4

Likes

34 likes

Total Posts

203 posts

Correct Reply

4 solutions
Top badges earned
Ignite 10
Boost 25
Give Back 25
Validate 10
Validate 1
View profile
TB3dock
Level 4

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
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

544 likes

Total Posts

663 posts

Correct Reply

190 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

544 likes

Total Posts

663 posts

Correct Reply

190 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

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
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

169 likes

Total Posts

175 posts

Correct Reply

54 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

169 likes

Total Posts

175 posts

Correct Reply

54 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

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