我正在尝试创建一个返回用户详细信息的REST Web服务。REST Web服务JSON格式
这里是我的代码:
//Actual web service methods implemented from here
@GET
@Path("login/{email}/{password}")
@Produces("application/json")
public Tourist loginUser(@PathParam("email") String email, @PathParam("password") String password) {
List<Tourist> tourists = super.findAll();
for (Tourist tourist : tourists) {
if (tourist.getEmail().equals(email) && tourist.getPassword().equals(password)) {
return tourist;
}
}
//if we got here the login failed
return null;
}
这将产生以下JSON:
{
"email": "[email protected]",
"fname": "Adrian",
"lname": "Olar",
"touristId": 1
}
我需要的是:
{"tourist":{
"email": "[email protected]",
"fname": "Adrian",
"lname": "Olar",
"touristId": 1
}
}
我需要什么添加到我的代码生产这个?
什么语言? Java的? –
是的,Java语言 –
这不是一个有效的JSON,所以你不能违反规范。你确定这正是你想要的吗? –