EntityType
- The Java type to marshall as Json.@Supports(value="application/json") public abstract class AbstractJsonWriter<EntityType> extends Object implements Writer<EntityType>
Writer
.
This class provides a easy way to produce json and also provides the current context: ctx
.
It provides you a JsonGenerator
to manage the marshalling.
The use of this class optimize the JsonFactory usage especially when aggregating marshallers.
Constructor and Description |
---|
AbstractJsonWriter() |
Modifier and Type | Method and Description |
---|---|
boolean |
accept(Class<?> clazz,
Type genericType,
javax.ws.rs.core.MediaType mediatype)
Checks if this marshaller can handle the marshalling request.
|
void |
write(EntityType entity,
Class<?> clazz,
Type genericType,
javax.ws.rs.core.MediaType mediatype,
OutputStream out)
Writes the entity to out
OutputStream using mediatype format. |
abstract void |
write(EntityType entity,
org.codehaus.jackson.JsonGenerator jg)
Implement this method to writes the entity in the provided
JsonGenerator . |
public boolean accept(Class<?> clazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
Marshaller
Please note it's useless to check that clazz is an instance of EntityType or if generic type and entity type are
compatible (unlike JAX-RS which just checks the clazz, not the generic type). It's also useless to check
Supports
is compatible with mediatype. This is already done by the MarshallerRegistry
This method implementation can use injected properties. So you can check the current RenderingContext
to
accept or reject a marshalling request.
accept
in interface Marshaller<EntityType>
clazz
- The type to marshall.genericType
- The generic type to marshall.mediatype
- The managed mimetype.public void write(EntityType entity, Class<?> clazz, Type genericType, javax.ws.rs.core.MediaType mediatype, OutputStream out) throws IOException
Writer
OutputStream
using mediatype format.
This method implementation can use injected properties.
write
in interface Writer<EntityType>
entity
- The entity to marshall.clazz
- The requested marshalled class.genericType
- The requested marshalled generic type.mediatype
- The target mediatype.out
- The output of this marshaller.IOException
- If some error append while writing entity to out.public abstract void write(EntityType entity, org.codehaus.jackson.JsonGenerator jg) throws IOException
JsonGenerator
.
This method implementation can use injected properties.
The JsonGenerator
's flushing is done by this abstract class, it's also not not necessary to flush it. Do
not close the provided JsonGenerator
. It may be used is another marshaller calling this one.
entity
- The entity to marshall as Json.jg
- The JsonGenerator
used to produce Json output.IOException
Copyright © 2015 Nuxeo SA. All rights reserved.