Interface MarshallerRegistry

All Known Implementing Classes:
MarshallerRegistryImpl

public interface MarshallerRegistry
Service to get specialize marshaller.

This service provides an extension point to register/deregister marshallers.

 
 <extension target="org.nuxeo.ecm.core.io.MarshallerRegistry" point="marshallers">
   <register class="org.nuxeo.ecm.core.io.marshallers.json.validation.ConstraintWriter" enable="true" />
   <register class="org.nuxeo.ecm.core.io.marshallers.json.validation.DocumentValidationReportWriter" enable="true" />
 </extension>
 
 

You can also register/deregister your marshaller programmatically by calling register(Class) and deregister(Class).

All marshallers are provided with injected properties.

You can get a Writer using:

You can get a Reader using:

If several marshaller matches a demand of the single instance, the registry use the following rules to choose one:

  • The marshaller with the greatest priority is choosen.
  • Then, Less instance is better: Instantiations.SINGLETON are preferred to Instantiations.PER_THREAD to Instantiations.EACH_TIME
  • Then, Expert is better: A marshaller which manage a subclass is prefered.
  • Then, references works: A subclass of an existing marshaller is not choosen. You have to specify an higher priority.
Since:
7.2
  • Method Details

    • clear

      void clear()
      Be careful !!! That's deregister all marshallers.
      Since:
      7.2
    • register

      void register(Class<?> marshaller) throws MarshallingException
      Makes a marshaller class available.
      Parameters:
      marshaller - The marshaller class.
      Throws:
      MarshallingException - If marshaller class is null or if it's not a valid marshaller.
      Since:
      7.2
    • deregister

      void deregister(Class<?> marshaller) throws MarshallingException
      Remove a marshaller from the registry.
      Parameters:
      marshaller - The marshaller class.
      Throws:
      MarshallingException - If marshaller class is null or if it's not a valid marshaller.
      Since:
      7.2
    • getWriter

      <T> Writer<T> getWriter(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides a Writer instance to manage marshalling of the given Java Type and mimetype.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A valid Writer instance.
      Since:
      7.2
    • getUniqueWriter

      <T> Writer<T> getUniqueWriter(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides a Writer instance to manage marshalling of the given Java Type and mimetype. It creates a new instance even for Instantiations.SINGLETON marshallers.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A valid Writer instance.
      Since:
      7.2
    • getAllWriters

      <T> Collection<Writer<T>> getAllWriters(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides all Writer instance that manage marshalling of the given Java Type and mimetype.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A list of valid Writer instance.
      Since:
      7.2
    • getWriter

      <T> Writer<T> getWriter(RenderingContext ctx, Class<T> marshalledClazz, javax.ws.rs.core.MediaType mediatype)
    • getReader

      <T> Reader<T> getReader(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides a Reader instance to manage marshalling of a mimetype in a Java Type.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A valid Reader instance.
      Since:
      7.2
    • getUniqueReader

      <T> Reader<T> getUniqueReader(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides a Reader instance to manage marshalling of a mimetype in a Java Type. It creates a new instance even for Instantiations.SINGLETON marshallers.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A valid Reader instance.
      Since:
      7.2
    • getAllReaders

      <T> Collection<Reader<T>> getAllReaders(RenderingContext ctx, Class<T> marshalledClazz, Type genericType, javax.ws.rs.core.MediaType mediatype)
      Provides all Reader instance that manage marshalling of a mimetype in a Java Type.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshalledClazz - The java type to manage.
      genericType - The generic Java type to manage.
      mediatype - The expected mimetype.
      Returns:
      A list of valid Reader instance.
      Since:
      7.2
    • getReader

      <T> Reader<T> getReader(RenderingContext ctx, Class<T> marshalledClazz, javax.ws.rs.core.MediaType mediatype)
    • getInstance

      <T> T getInstance(RenderingContext ctx, Class<T> marshallerClass)
      Provides an instance of a given marshaller class.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshallerClass - A valid marshaller instance.
      Returns:
      A valid marshaller instance.
      Since:
      7.2
    • getUniqueInstance

      <T> T getUniqueInstance(RenderingContext ctx, Class<T> marshallerClass)
      Provides an instance of the given marshaller class. It creates a new instance even for Instantiations.SINGLETON marshallers.
      Parameters:
      ctx - The marshalling context (see RenderingContext).
      marshallerClass - A valid marshaller instance.
      Returns:
      A valid marshaller instance.
      Since:
      7.2