Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Json object giving null value after sending json array to the sling Servlet

Avatar

Community Advisor

Hi All,

         I have created Sling Servlet and  I wanted to pass json raw data to the Slingservlet but it is showing null values.

IMG_20211102_075919.jpg

IMG_20211102_075836.jpgplease check anything that I missed.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @Sanjay_Bangar ,

 

When doing a ajax call use something like below

 

var square = {};

square.length = 10;

square.width = 10;

$.ajax(

url: url,

data: JSON.stringify(square),

dataType: “json”

contentType: “application/json”,

 

);

 

while reading in servlet you can use like below:

 

String requestBody = request.getReader().lines().collect(Collectirs.joining());


you can use any Utils class to convert from string to json or java bean.

 

Thanks!

 

 

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @Sanjay_Bangar 

 

Try 2nd the solution in the below link: https://stackoverflow.com/questions/33896136/read-json-message-from-http-post-request-in-java

 

Hope this helps.

 

Thanks,

Kiran Vedantam

Avatar

Correct answer by
Level 4

Hi @Sanjay_Bangar ,

 

When doing a ajax call use something like below

 

var square = {};

square.length = 10;

square.width = 10;

$.ajax(

url: url,

data: JSON.stringify(square),

dataType: “json”

contentType: “application/json”,

 

);

 

while reading in servlet you can use like below:

 

String requestBody = request.getReader().lines().collect(Collectirs.joining());


you can use any Utils class to convert from string to json or java bean.

 

Thanks!