How correctly produce JSON by RESTful web service?

后端 未结 5 1155
无人共我
无人共我 2020-12-08 15:48

I am writing a web service the first time. I created a RESTful web service based on Jersey. And I want to produce JSON. What do I need to do to generate the

5条回答
  •  天命终不由人
    2020-12-08 16:25

    @GET
    @Path("/friends")
    @Produces(MediaType.APPLICATION_JSON)
    public String getFriends() {
    
        // here you can return any bean also it will automatically convert into json 
        return "{'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}";
    }
    

提交回复
热议问题