Java – use a body that is not entirely JSON

I am developing a web application based on Jersey rest API I am developing the post service according to the client requirements (input parameters in JSON format) and it works normally Now they want to change the input format, as shown below Now I get 415 errors (unsupported media types)

This is the old JSON format, which works well:

{
    "weight": 5.0,"length": 1.5,"width": 2.7,"height": 0.7
}

This format needs to be sent by the client

{
weight = 12;
with = 78;
height = 78;
length = 5;
}

This is my post service:

@POST
@Path("/insert")
@Consumes({MediaType.TEXT_PLAIN})
@Produces({MediaType.APPLICATION_JSON})

I've used it before

@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})

Solution

It is no longer JSON have a look http://www.json.org/ , you will see that the parameter name string must be enclosed in double quotes So you must decide to listen to the client and create your own messagebodyreader to handle this custom format, or tell the client that they need to send valid JSON

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>