MessageBodyWriter not found for media type=application/json

丶灬走出姿态 提交于 2019-12-02 00:49:27

Normally the auto-discoverable feature registers the MoxyJsonFeature. I am not sure how it works wit the embedded Jetty. But if it is not register, we can register it ourselves. There is an <init-param> that allows us to add a arbitrary number of providers, separated by a comma. In a web.xml it would be

<init-param>
    <param-name>jersey.config.server.provider.classnames</param-name>
    <param-value>
        org.glassfish.jersey.moxy.json.MoxyJsonFeature,
        org.bar.otherresources.MyCatResource
    </param-value>
</init-param>

So in your Jetty code, you could do

jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
                               "org.glassfish.jersey.moxy.json.MoxyJsonFeature");

The MoxyJsonFeature registers the MessageBodyWriter and MessageBodyReader required to marshal and unmarshal our POJOS to and from JSON. See more at JAX-RS Entity Providers, and continued in Support for Common Media Type Representations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!