4

Here is the Rest Controller Service signature

@RequestMapping(value = "/getFilteredReport", method = RequestMethod.POST)
 public void getFilteredReport(@RequestBody FilteredReportVO filteredReportVO,HttpServletRequest request,HttpServletResponse response) {

Now below is the JSON structure I am sending

{
"filterAttributesFactory":{
"930000":{
"metaDataId":930000,
"displayText":"Select Category",
"attributeType":211009,
"userInputValue":null,
"dropDownoptions":null,
"isMandatory":false,
"isDropDown":false,
"defaultValue":null,
"isdefaultValue":false,
"constraintId":null
},
"930001":{
"metaDataId":930001,
"displayText":"Item Status",
"attributeType":211005,
"userInputValue":null,
"dropDownoptions":{
"157005":"FC - fake scrap",
 "157006":"FH - firearm hold",
 "157008":"IN - inventory"
  },
  "isMandatory":false,
  "isDropDown":true,
  "defaultValue":null,
  "isdefaultValue":false,
  "constraintId":213007
  }
 },
"reportId":132030,
"location":1202
}

Here is the FilteredReportVO POJO

public class FilteredReportVO {

private HashMap<Integer,FilterAttributeVO> filterAttributesFactory=new HashMap<Integer,FilterAttributeVO>();

private Integer reportId;

private Long location; .....GETTERS and setters below

FilterAttributeVO pojo structure is below..

public class FilterAttributeVO {
Integer metaDataId;
//String elementName;
String displayText;
Integer attributeType;
Object userInputValue;
Map<Integer,String> dropDownoptions;
Boolean isMandatory=false;;
Boolean isDropDown=false;
Object defaultValue;
Boolean isdefaultValue=false;
Integer constraintId=null;...Getters n setters..

I am hitting the service through POSTMAN plugin. Getting error:

"The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications".

FYI in POSTMAN I am putting the JSON structure inside "Body", selected "raw", type as "JSON(application/json)".

Notice I am using 2 object type attributes userInputValue and defaultValue inside FilteredAttributeVO. R we allowed to keep object type?

Where is the problem here?

smruti ranjan
  • 741
  • 2
  • 9
  • 23
  • 1
    You shoul post class FilteredReportVO also. Maybe there is an error with "dropDownoptions", that might be "dropDownOptions", following your notation. – Wakachopo May 24 '16 at 06:24
  • extra comma after "157008":"IN - inventory" attribute. always run through json formatter if not sure. – s7vr May 24 '16 at 06:39
  • @Shiv sorry dude it was my bad.Actually the extra comma got added while editing it. This is not in the actual JSON structure.I have updated the question..Plz see – smruti ranjan May 24 '16 at 07:10
  • I have updated the question with VO structures plz have a look. – smruti ranjan May 24 '16 at 07:10

2 Answers2

2

Input Json is not valid If you see the screen shot of your input JSON with JSONlint your json is not valid.Please fix your json object and validate it using jsonlint

you can try following code in your Test to Resolve this issue coz Spring internally uses Jackson library

ObjectMapper mapper = new ObjectMapper();
Staff obj = mapper.readValue(jsonInString, FilteredReportVO.class);

If this works fine then their should be issue with your Postman RequestBody preparation otherwise you will get detailed stacktrace :)

Aniket Kulkarni
  • 1,985
  • 2
  • 17
  • 22
1

The problem was with FilteredReportVO POJO. I was setting values of the attributes "location" and "reportId" through a constructor. No setter methods were defined for these 2 attributes.

It was my bad, if I would have posted the complete POJO class u guys must have figured it out. Anyway thanks everyone for ur help

smruti ranjan
  • 741
  • 2
  • 9
  • 23