Verified Owner
Top Description Fields Constructors Methods
org.jabref.http.dto

public Class GsonMessageBodyReader

extends Object
implements MessageBodyReader<Object>
Class Inheritance
All Implemented Interfaces
jakarta.ws.rs.ext.MessageBodyReader
Annotations
@Provider
@Consumes:application/json
Imports
java.io.IOException, .InputStream, .InputStreamReader, .Reader, java.lang.annotation.Annotation, java.lang.reflect.Type, java.nio.charset.StandardCharsets, com.google.gson.Gson, .JsonSyntaxException, jakarta.inject.Inject, jakarta.ws.rs.BadRequestException, .Consumes, jakarta.ws.rs.core.MediaType, .MultivaluedMap, jakarta.ws.rs.ext.MessageBodyReader, .Provider

Reads application/json request bodies into POJOs via Gson so resources can declare strongly-typed parameters.

Field Summary

Modifier and TypeField and Description
private Gson

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements jakarta.ws.rs.ext.MessageBodyReader.isReadable.

Decline types handled by the container's built-in readers (raw JSON text / streams).

public Object
readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)

Implements jakarta.ws.rs.ext.MessageBodyReader.readFrom.

Read a type from the InputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gsonback to summary
private Gson gson
Annotations
@Inject

Constructor Detail

GsonMessageBodyReaderback to summary
public GsonMessageBodyReader()

Method Detail

isReadableback to summary
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Implements jakarta.ws.rs.ext.MessageBodyReader.isReadable.

Decline types handled by the container's built-in readers (raw JSON text / streams). Resources such as CommandResource and MapResource take the body as String and parse it themselves; Gson would fail those unless the body were a quoted JSON string.

Annotations
@Override
readFromback to summary
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException

Implements jakarta.ws.rs.ext.MessageBodyReader.readFrom.

Doc from jakarta.ws.rs.ext.MessageBodyReader.readFrom.

Read a type from the InputStream.

In case the entity input stream is empty, the reader is expected to either return a Java representation of a zero-length entity or throw a jakarta.ws.rs.core.NoContentException in case no zero-length entity representation is defined for the supported Java type. A NoContentException, if thrown by a message body reader while reading a server request entity, is automatically translated by JAX-RS server runtime into a jakarta.ws.rs.BadRequestException wrapping the original NoContentException and rethrown for a standard processing by the registered exception mappers.

Annotations
@Override
Exceptions
IOException:
if an IO error arises. In case the entity input stream is empty and the reader is not able to produce a Java representation for a zero-length entity, NoContentException is expected to be thrown.