如何将 DTO 传递给 Restful 网络服务

How to Pass the DTO to the Restful web services

这可能是个简单的问题。我试过谷歌搜索但没有运气。 我有一个 DTO,它从客户端传递并由 restful 网络服务使用。但是得到这个异常

 Mapping exception to XML
avax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type

这是我的restful方法。

    @PUT
    @Path("microservice/persist")
    @Consumes("application/json")
    public long update(AsyncJobDTO asyncJobDTO){
      //calling EJB and returing the value
      }

这是我的 restful 电话

http://localhost:9090/nexterp-war/rest/api/Jobupdate/microservice/persist?format=format.json

这是因为没有随请求一起发送的接受 header。您需要发送带有客户端代码的 AcceptsContent-Type header。

既然你的申请被接受了json,应该是

<code>'Accept': 'application/json'</code>
<code>'Content-Type': 'application/json'</code>

SO 中的类似帖子 Http 415 Unsupported Media type error with JSON, Error 415 Unsupported Media Type: POST not reaching REST if JSON, but it does if XML