gpt4 book ai didi

json - 没有根元素名称resteasy响应

转载 作者:行者123 更新时间:2023-12-01 00:02:42 24 4
gpt4 key购买 nike

我在返回带有指定对象的根名称的对象列表时遇到了一些问题。我尝试了几种不同的东西。我确信我像往常一样在做一些非常愚蠢的事情,我感谢任何帮助。

这是我的对象

@XmlRootElement
@JsonRootName(value = "Bixasset")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Produces("application/json")
@Indexed
public class Bixasset implements java.io.Serializable {
@Id
private UUID id;

private Client client;

private String name;

private String asseturl;
private Character active;
private Integer width;
private Integer height;
private String thumbnailurl;
private Date createddate;
private String filetype;
private String category;


public Bixasset() {
}

public Bixasset(UUID id) {
this.id = id;
}

public Bixasset(UUID id, Client client, String name, String asseturl,Character active, Integer width, Integer height, String thumbnailurl
,Date createddate, String filetype, String category) {
this.id = id;
this.client = client;
this.name = name;
this.asseturl = asseturl;
this.active = active;
this.width = width;
this.height = height;
this.thumbnailurl = thumbnailurl;
this.createddate = createddate;
this.filetype = filetype;
this.category = category;


}



public UUID getId() {
return this.id;
}

public void setId(UUID id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
@JoinColumn(name="clientid")
public Client getClient() {
return this.client;
}

public void setClient(Client client) {
this.client = client;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAsseturl() {
return asseturl;
}

public void setAsseturl(String asseturl) {
this.asseturl = asseturl;
}

public Character getActive() {
return active;
}

public void setActive(Character active) {
this.active = active;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}

public Integer getHeight() {
return height;
}

public void setHeight(Integer height) {
this.height = height;
}

public String getThumbnailurl() {
return thumbnailurl;
}

public void setThumbnailurl(String thumbnailurl) {
this.thumbnailurl = thumbnailurl;
}

public Date getCreateddate() {
return createddate;
}

public void setCreateddate(Date createddate) {
this.createddate = createddate;
}

public String getFiletype() {
return filetype;
}

public void setFiletype(String filetype) {
this.filetype = filetype;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

}

这是我的方法
@Path("/bixasset/")
@Produces(MediaType.APPLICATION_JSON)
public Response queryBixAsset(@QueryParam("id") String id, @QueryParam("filetype") String filetype, @QueryParam("category") String category, @QueryParam("token") String token) {
try{

List<Bixasset> results = new ArrayList<Bixasset>();


UUID ClientId = dAL.validateToken(token);

if(token != null && ClientId != null){


String query ="FROM Bixasset WHERE client.id = '" + ClientId + "' ";


if(id != null && !id.equals(""))
query += " AND id = '" + id + "'";

if(filetype != null && !filetype.equals(""))
query += " AND filetype.id = '" + filetype + "'";

if(category != null && !category.equals(""))
query += " AND category = '" + category + "'";




query+= " LIMIT 1000";
results = dAL.query(query);
System.out.println("query size" + results.size());


}else{
return Response.status(401).build();
}


return Response.ok(results).build();
}catch(Exception e){
return Response.status(400).build();
}
}

这是我的结果
   [
{
"id": "99f516a2-f7ef-4bc9-a627-73981a2fc3ae",
"client": {
"id": "388e16d6-d35e-4f8c-bba5-b1147b824473",
"reseller": null,
"name": "Phizzle",
"createddate": 1357554435574,
"address1": "123",
"address2": "",
"city": "San Francisco",
"state": "CA",
"postalcode": "80130",
"country": "USA",
"description": "Phizzle Master Client"
},
"name": "gears_animated.gif",
"asseturl": "https://s3.amazonaws.com/asdad/99f516a2-f7ef-4bc9-a627-73981a2fc3ae.gif",
"active": "0",
"width": 141,
"height": 141,
"thumbnailurl": "https://s3.amazonaws.com/dadadsda/99f516a2-f7ef-4bc9-a627-73981a2fc3ae__thumbnail.jpg",
"createddate": 1380927929287,
"filetype": "image/gif",
"category": "Images"
}
]

希望我的结果看起来像
   {"Bixasset" [
{
"id": "99f516a2-f7ef-4bc9-a627-73981a2fc3ae",
"client": {
"id": "388e16d6-d35e-4f8c-bba5-b1147b824473",
"reseller": null,
"name": "Phizzle",
"createddate": 1357554435574,
"address1": "123",
"address2": "",
"city": "San Francisco",
"state": "CA",
"postalcode": "80130",
"country": "USA",
"description": "Phizzle Master Client"
},
"name": "gears_animated.gif",
"asseturl": "https://s3.amazonaws.com/adsdadd/99f516a2-f7ef-4bc9-a627-73981a2fc3ae.gif",
"active": "0",
"width": 141,
"height": 141,
"thumbnailurl": "https://s3.amazonaws.com/adadsd/99f516a2-f7ef-4bc9-a627-73981a2fc3ae__thumbnail.jpg",
"createddate": 1380927929287,
"filetype": "image/gif",
"category": "Images"
}
] }

最佳答案

您是否尝试过设置 @XmlRootElement 的 Annotation 变量而不是使用 @JsonRootName?
我的意思是:

@XmlRootElement(name = "Bixasset")

关于json - 没有根元素名称resteasy响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19212586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com