JSON-请求 Jersey 导致“400 Bad Request”

JSON-Request to Jersey causes "400 Bad Request"

我有一个球衣服务器示例,它适用于 XML,但不适用于 JSON。

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;

@Path("JsonExample")
public class JsonExample {

    @XmlRootElement
    public static class Input {
        public String text;
    }

    @POST
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public String test(Input i) {
        return i.text;
    }

}

如果我将此 xml 请求作为 application/xml 发送到服务器,一切正常,响应为 a(对于 http://localhost:8080/App/rest/JsonExample 作为 POST )

<input><text>a</text></input>

我在 utilities-online.info 将其翻译成 JSON 并以 application/json 的形式发送到相同的 URL,使用相同的参数,但出现错误“400 Bad Request “

{
  "input": { "text": "a" }
}

环境:

我尝试过的:

在写我的问题时,我看到了一个例外,即 "input" 不应作为字段。正确的 JSON-请求必须是:

{ "text": "a" }