簡體   English   中英

415 RESTful Web服務中不支持的媒體類型

[英]415 Unsupported Media Type in RESTful webservice

我編寫了一個RESTful Web服務,它返回一個單詞列表。 Word類被注釋為根元素。

我在休息客戶端測試了它,它生成了415 Unsupported MediaType。 任何人都可以幫助做其他事情來使其發揮作用。

@POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @Path("getCategoryWordListFromJSON")
    public List<Word> getLearnWordListByCategory(JSONObject jsonObject) {
        List<Word> wordList = new ArrayList<Word>();
        try {
            String category = (String) jsonObject.get("category");
            LOGGER.log(Level.INFO, category);
            LearnWordListDao wordListDao = new LearnWordListDaoImpl();
            wordList.addAll(wordListDao.getCategoryListFor(category));
        } catch (JSONException e) {
            LOGGER.log(Level.INFO, e.getMessage());
        }
        return wordList;
    }

HiAllwyn,

返回列表有很多種方法。 在這里,它無法解析代碼中提供的List對象。 請嘗試這....它的工作.... :)

@POST
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes(MediaType.APPLICATION_JSON)
@Path("getCategoryWordListFromJSON")
public Response getLearnWordListByCategory(JSONObject jsonObject) {
    List<Word> wordList = new ArrayList<Word>();
    try {
        String category = (String) jsonObject.get("category");
        LOGGER.log(Level.INFO, category);
        LearnWordListDao wordListDao = new LearnWordListDaoImpl();
        wordList.addAll(wordListDao.getCategoryListFor(category));
    } catch (JSONException e) {
        LOGGER.log(Level.INFO, e.getMessage());
    }


final GenericEntity<List<Word>> entity = new GenericEntity<List<Word>>(wordList) { };
       return Response.ok().entity(entity).build();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM