大家好,请告诉我如何在执行REST后保持POJO类的顺序。
@GET
@Path("/Encounter")
@Produces(MediaType.APPLICATION_JSON)
@JsonPropertyOrder(alphabetic = false)
public List<Encounter> getEncounterDetails(@QueryParam("patientId") Long patientId) throws JSONException, IOException {
List<Encounter> enlist = new ArrayList<Encounter>();
service = new MyappImpl();
enlist = service.getEncounterDetails(patientId);
return enlist;
}
输出 { “当前”:空, “遭遇ID”:67, “名称”:“xyz”, “逾期”:空, “患者 ID”:624 }
但是我的 POJO 类顺序是 遇到 ID , 名字...
最佳答案
按照您定义的顺序获取 Rest API json 输出。
这里写了一个示例。请定义 Json 属性顺序以获取您想要的值。
package com.example.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({ "id", "name", "dept"})
public class Student {
@JsonProperty("id")
private int id;
@JsonProperty("name")
private String name;
@JsonProperty("dept")
private String dept;
//getter and Setter
}
输出:
[
{
"id": 1,
"name": "Name 1",
"dept": "CSE"
},
{
"id": 2,
"name": "Name 2",
"dept": "B-Com"
}
]
关于java - 请告诉我如何在执行 REST url(JERSEY) 后保持 POJO 类的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48082614/