Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that your JAX-RS implementation (Jersey in this case) doesn't know how to map <code>application/json</code> content into a <code>String</code>. You'll need to register a <code>MessageBodyReader&lt;String&gt;</code> implementation that is annotated with <code>@Consumes(MediaType.APPLICATION_JSON)</code>.</p> <p><strong>Addendum</strong></p> <p>Implementing a <code>MessageBodyReader</code> that converts to <code>String</code> is straightforward.</p> <pre><code>@Provider @Consumes(MediaType.APPLICATION_JSON) public class JsonStringReader implements MessageBodyReader&lt;String&gt; { @Override public boolean isReadable( Class&lt;?&gt; type, Type genericType, Annotation[] annotations, MediaType mediaType ) {return type == String.class;} @Override public String readFrom( Class&lt;String&gt; type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap&lt;String, String&gt; httpHeaders, InputStream entityStream ) throws IOException, WebApplicationException { final String charsetName = mediaType.getParameters().get(MediaType.CHARSET_PARAMETER); final Charset charset = charsetName == null ? Charset.forName("UTF-8") : Charset.forName(charsetName); final StringBuilder builder = new StringBuilder(); final Reader reader = new InputStreamReader(entityStream, charset); final CharBuffer buffer = CharBuffer.allocate(1024); while (reader.read(buffer) != -1) { buffer.flip(); builder.append(buffer); buffer.clear(); } return builder.toString(); } } </code></pre> <p>There are several ways to register a entity provider with a JAX-RS implementation. The way that's probably easier with Jersey is to add the following to your <code>web.xml</code>:</p> <pre><code>&lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;pkg.that.contains.the.messagereader&lt;/param-value&gt; &lt;/init-param&gt; </code></pre> <p>Further information on creating entity providers for Jersey can be found here: <a href="https://jersey.java.net/documentation/latest/message-body-workers.html" rel="nofollow">https://jersey.java.net/documentation/latest/message-body-workers.html</a></p> <p>More information on configuring Jersey can be found here: <a href="http://jersey.java.net/nonav/apidocs/1.8/jersey/com/sun/jersey/spi/container/servlet/ServletContainer.html" rel="nofollow">http://jersey.java.net/nonav/apidocs/1.8/jersey/com/sun/jersey/spi/container/servlet/ServletContainer.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload