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 correct JSON type of my web service?
Here's one of my methods:
@GET
@Path("/friends")
@Produces("application/json")
public String getFriends() {
return "{'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}";
}
Is it sufficient that I simply point out annotation @Produces("application/json")
for my method? Then this method may return any type of object? Or only String? Do I need additional processing or transformation of these objects?
Please help me as a beginner to deal with these issues. Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…