我正在尝试将一个方法添加到现有的Jersey Rest服务中,以获取对象列表的帖子。它不喜欢我做这件事的方式,或者我遗漏了一个依赖项或者别的什么……任何帮助都是非常感谢的。
服务标记:
@POST
@Consumes({ MediaType.APPLICATION_JSON })
public boolean update(@HeaderParam("Authorization") String token, @FormParam("photos") ArrayList<UiPhoto> uiPhotos) {错误:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public boolean com.creo.services.PhotoService.update(java.lang.String,java.util.ArrayList) at parameter at index 1
SEVERE: Method, public boolean com.creo.services.PhotoService.update(java.lang.String,java.util.ArrayList), annotated with POST of resource, class com.creo.services.PhotoService, is not recognized as valid resource method.这将进行编译,但对服务上的方法的请求会因这些错误而爆炸。
发布于 2014-06-01 09:52:22
您可能应该包括ArrayList的数据类型。
如果您在POST请求的主体中发送编码为JSON或XML的Item对象,下面的虚拟示例就可以工作。
@POST
@Path("/{shoppingListId}/additem")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addItemToShoppingList(
@PathParam("shoppingListId") String id, Item item) {
String itemId = UUID.randomUUID().toString();
item.setId(itemId);
if (listNames.containsKey(id)) {
if (listItems.get(id) != null) {
listItems.get(id).add(item);
} else {
ArrayList<Item> items = new ArrayList<Item>();
items.add(item);
listItems.put(id, items);
}
} else {
throw new WebApplicationException(404);
}
return Response.status(201).entity(item).build();
}对象项需要使用@XmlRootElement进行注释。
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Item {
String id;
String name;
String price;
// getters and setters ...
}发布于 2014-06-02 13:10:00
使用UiPhoto[]而不是ArrayList。希望能有所帮助。
https://stackoverflow.com/questions/23976012
复制相似问题