【发布时间】:2015-11-02 04:17:54
【问题描述】:
我有一个小问题,这是因为我对 REST 和 JSON 的体验不是很好!
不过我有这个服务
@Path("/baseService")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML,MediaType.APPLICATION_XML})
public interface BaseService {
@POST
@Path("/registration")
@Transactional
public UserTO register(@RequestBody UserTO userto);
我想从客户端发送一个 json 来测试服务
如果我在没有 json 的情况下调用他,一切正常:
resp=client.post(userTO);
但我不知道如何调用它发送和 json(让 spring jackson 为您将它从 json 转换为 UserTO 对象)在线阅读我尝试的一些解决方案:
client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).query("mail", "test").query("name", "test").query("psw", "test").query("role", "cassa").query("surname", "fsddsf").query("userName", "fsdfs").post(UserTO.class);
或
resp=client.accept(MediaType.APPLICATION_JSON).post(inputJsonObj);
我该怎么做?请帮忙!
【问题讨论】: