I have the following controller code.
@RequestMapping(value = "/testService/test", produces = MediaType.APPLICATION_JSON_VALUE)
public HttpEntity<TestBean> test(@RequestParam Map<String,String> testReq) {
...
List<Test> objList=testRepository.test();
testBean.setObjects(objList);
...
return new ResponseEntity<TestBean>(testBean, HttpStatus.OK);
}
TestBean holds a list of Test objects(with getters/setters and some other attributes) as below
private List<Test> objects;
Test class is defined as below
@Entity
@Table(name="TEST")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Test implements Serializable{
private static final long serialVersionUID = -5319848003675140194L;
@JsonIgnore
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="TEST_ID")
Integer testId;
...
test() method is defined as below.
@Query(value="SELECT ...", nativeQuery=true)
List<Test> test();
The json output I see is as below
{"requestId":"testRequestId","objects":[[1,"Test name"],[2,"Test name2"]],"status":"Success"}
Other things being okay, my question is why is the objects list being output in that way instead of like this
{"testId":1,"testName":"Test name"}
For another similar objects that I am using I see the output as expected(in proper json format).
Please note that I have not copied the actual code, but typed the code with changed names, so please ignore any syntax errors that you may see in the code.
Could someone please advise on how can I get a proper json in the output?
TestandTestBeanclasses. Do any of these classes contain Jackson annotations? The array serialization happens when theBeanAsArraySerializeris used, which might be activated if you have certain@JsonFormatannotations.@JsonIgnoreannotation on thetestIdfield (unless it's a different number in the response).@JsonPropertyOrder({ "requestId", "objects" }) public class TestBean extends ResourceSupport {