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

public Class GsonMessageBodyWriter

extends Object
implements MessageBodyWriter<Object>
Class Inheritance
All Implemented Interfaces
jakarta.ws.rs.ext.MessageBodyWriter
Annotations
@Provider
@Produces:application/json
Imports
java.io.IOException, .OutputStream, .OutputStreamWriter, .Writer, java.lang.annotation.Annotation, java.lang.reflect.Type, java.nio.charset.StandardCharsets, com.google.gson.Gson, jakarta.inject.Inject, jakarta.ws.rs.Produces, jakarta.ws.rs.core.MediaType, .MultivaluedMap, jakarta.ws.rs.ext.MessageBodyWriter, .Provider

Serializes resource return values into application/json via Gson so resources can return strongly-typed POJOs. Skips primitive types (String, byte[], InputStream) so JAX-RS' built-in writers handle them.

Field Summary

Modifier and TypeField and Description
private Gson

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements jakarta.ws.rs.ext.MessageBodyWriter.isWriteable.

Ascertain if the MessageBodyWriter supports a particular type.

public void
writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)

Implements jakarta.ws.rs.ext.MessageBodyWriter.writeTo.

Write a type to an HTTP message.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gsonback to summary
private Gson gson
Annotations
@Inject

Constructor Detail

GsonMessageBodyWriterback to summary
public GsonMessageBodyWriter()

Method Detail

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

Implements jakarta.ws.rs.ext.MessageBodyWriter.isWriteable.

Doc from jakarta.ws.rs.ext.MessageBodyWriter.isWriteable.

Ascertain if the MessageBodyWriter supports a particular type.

Annotations
@Override
writeToback to summary
public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException

Implements jakarta.ws.rs.ext.MessageBodyWriter.writeTo.

Doc from jakarta.ws.rs.ext.MessageBodyWriter.writeTo.

Write a type to an HTTP message. The message header map is mutable but any changes must be made before writing to the output stream since the headers will be flushed prior to writing the message body.

Annotations
@Override
Exceptions
IOException:
if an IO error arises.