public class MarshallerRegistry extends Object
This class allows marshaller lookup based on root object class and media type, and attempts to create new marshallers for a given class and media type combination.
Constructor and Description |
---|
MarshallerRegistry()
Construct a MarshallerRegistry instance.
|
Modifier and Type | Method and Description |
---|---|
protected Marshaller |
createDefaultMarshaller(Class clzRoot,
String sMediaType)
Create default marshaller for the specified class and media type.
|
protected String |
createKey(Class clzRoot,
String sMediaType)
Create a key for the marshallers map.
|
protected Marshaller |
createMarshaller(Class<?> clzRoot,
String sMediaType,
Class<?> clzMarshaller)
Create marshaller instance.
|
Marshaller |
getMarshaller(Class clzRoot,
javax.ws.rs.core.MediaType mediaType)
Return the marshaller for the specified root class and media type.
|
Marshaller |
getMarshaller(Class clzRoot,
String sMediaType)
Return the marshaller for the specified root class and media type.
|
void |
registerMarshaller(Class clzRoot,
javax.ws.rs.core.MediaType mediaType,
Class clzMarshaller)
Register a marshaller for the specified root class and media type.
|
void |
registerMarshaller(Class clzRoot,
javax.ws.rs.core.MediaType mediaType,
Marshaller marshaller)
Register a marshaller for the specified root class and media type.
|
void |
registerMarshaller(Class clzRoot,
String sMediaType,
Class clzMarshaller)
Register a marshaller for the specified root class and media type.
|
void |
registerMarshaller(Class clzRoot,
String sMediaType,
Marshaller marshaller)
Register a marshaller for the specified root class and media type.
|
void |
setDefaultMarshaller(javax.ws.rs.core.MediaType mediaType,
Class clzMarshaller)
Configure the default marshaller class for the specified media type.
|
void |
setDefaultMarshaller(String sMediaType,
Class clzMarshaller)
Configure the default marshaller class for the specified media type.
|
void |
setDefaultMarshallers(Map<String,Class> mapMarshallers)
Configure the default marshaller classes for the corresponding media types.
|
public MarshallerRegistry()
By default, a JacksonJsonMarshaller
will be used for JSON
marshalling and a JaxbXmlMarshaller
for XML marshalling. You
can override this behavior by calling the
setDefaultMarshaller(MediaType, Class)
method.
public Marshaller getMarshaller(Class clzRoot, javax.ws.rs.core.MediaType mediaType)
clzRoot
- root object classmediaType
- media typepublic Marshaller getMarshaller(Class clzRoot, String sMediaType)
clzRoot
- root object classsMediaType
- media typepublic void registerMarshaller(Class clzRoot, javax.ws.rs.core.MediaType mediaType, Class clzMarshaller)
clzRoot
- root object classmediaType
- media typeclzMarshaller
- marshaller classpublic void registerMarshaller(Class clzRoot, String sMediaType, Class clzMarshaller)
clzRoot
- root object classsMediaType
- media typeclzMarshaller
- marshaller classpublic void registerMarshaller(Class clzRoot, javax.ws.rs.core.MediaType mediaType, Marshaller marshaller)
clzRoot
- root object classmediaType
- media typemarshaller
- marshaller to registerpublic void registerMarshaller(Class clzRoot, String sMediaType, Marshaller marshaller)
clzRoot
- root object classsMediaType
- media typemarshaller
- marshaller to registerpublic void setDefaultMarshaller(javax.ws.rs.core.MediaType mediaType, Class clzMarshaller)
mediaType
- media type to set default marshaller forclzMarshaller
- default marshaller classpublic void setDefaultMarshaller(String sMediaType, Class clzMarshaller)
sMediaType
- media type to set default marshaller forclzMarshaller
- default marshaller classpublic void setDefaultMarshallers(Map<String,Class> mapMarshallers)
mapMarshallers
- a map of REST marshaller classes keyed by media typeprotected String createKey(Class clzRoot, String sMediaType)
clzRoot
- root object classsMediaType
- media typeprotected Marshaller createDefaultMarshaller(Class clzRoot, String sMediaType)
clzRoot
- root object classsMediaType
- media typeprotected Marshaller createMarshaller(Class<?> clzRoot, String sMediaType, Class<?> clzMarshaller)
clzRoot
- root object classsMediaType
- media typeclzMarshaller
- marshaller class