Jersey的新功能 - 在资源中获取不受支持的媒体类型

Mar*_*ior 1 rest json jax-ws jersey

我是泽西和REST的新手所以请原谅,如果我的问题太愚蠢了.我有一个名为Places的简单资源,它应该支持一个GET基于输入变量返回一些兴趣点的操作.这是输入字符串和类:

错误:

HTTP 415 - Unsupported Media Type
Run Code Online (Sandbox Code Playgroud)

输入网址:

http://localhost:8080/RESTGO/rest/places?latitude=2&longitude=3&radius=3&types=food
Run Code Online (Sandbox Code Playgroud)

类:

@Path("/places")
public class Places {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public JSONObject getPlaces(@QueryParam("latitude") double latitude,
            @QueryParam("longitude") double longitude,
            @QueryParam("radius") int radius,
            @QueryParam("types") String types,
            @DefaultValue("true") boolean sensor) {
        GooglePlacesClient google = new GooglePlacesClient();
        JSONObject json = null;

        try {
            String response = google.performPlacesSearch(latitude, longitude, radius, types, sensor);
            json = new JSONObject(response);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

@DefaultValue不行不通@QueryParam.尝试将@QueryParam注释添加到sensor-argument(请参阅DefaultValue javadoc)