捕获JSON数据?邮差数据将在控制台中打印出来

时间:2016-08-01 04:49:45

标签: java json rest jax-rs

我有一个Dto课: - Company.java

public class Company {

    private String companyId;
    private String companyName;

    Company(){
    }

    public String getCompanyId() {
        return companyId;
    }
    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }
    public String getCompanyName() {
        return companyName;
    }
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }   
}

然后我有一个serviceInterface.java

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes({"application/xml", "application/json",
    "application/x-www-form-urlencoded"})
@Path("/demoJson")
public Response demoJson(Company company);

ServiceImpl.java

public Response demoJson(Company company) {
    String result = "Company created : " + company;
    return Response.status(201).entity(result).build();
}

通过邮递员发送的Json数据: -

{
   "comapanyId":"123";
   "companyName":"Google";
}

通过邮递员发送的Json Data正在控制台中打印出来。我已经添加了杰克逊的依赖...我在这里缺少什么......我是一个新手,因为任何愚蠢的错误。

0 个答案:

没有答案