java.lang.Object
org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
org.apache.hadoop.yarn.server.resourcemanager.webapp.jsonprovider.ExcludeRootJSONProvider
All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>

@Provider @Produces("application/json") @Consumes("application/json") public class ExcludeRootJSONProvider extends org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
A custom JSON provider that extends MOXyJsonProvider to handle JSON marshalling and unmarshalling without including the root element for configured classes.

This provider integrates with EclipseLink MOXy and the JAX-RS runtime (annotated with Provider), and it is configured to both produce and consume application/json content types. It uses a ClassSerialisationConfig to determine which classes should be serialized and deserialized without a root element in the resulting JSON.

During marshalling and unmarshalling, this provider sets the MOXy-specific properties:
  • MarshallerProperties.JSON_INCLUDE_ROOT = false
  • MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS = false
ensuring that the JSON representation excludes the root element and does not include empty collections. This is useful when interoperating with APIs that expect flat JSON structures or when simplifying payloads for lightweight clients.

This class also provides detailed trace-level logging to help developers verify which entity types are being handled by this provider and how JSON binding is applied.

See Also:
  • Field Summary

    Fields inherited from class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider

    providers
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    ExcludeRootJSONProvider(org.apache.hadoop.conf.Configuration conf)
    Constructs a new ExcludeRootJSONProvider instance and initializes its ClassSerialisationConfig based on the provided application configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
    boolean
    isWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
    protected void
    preReadFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders, javax.xml.bind.Unmarshaller unmarshaller)
    protected void
    preWriteTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, javax.xml.bind.Marshaller marshaller)

    Methods inherited from class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider

    getAttributePrefix, getDomainClass, getDomainClasses, getJAXBContext, getNamespacePrefixMapper, getNamespaceSeparator, getSize, getValueWrapper, isFormattedOutput, isIncludeRoot, isMarshalEmptyCollections, isWrapperAsArrayName, readFrom, setAttributePrefix, setFormattedOutput, setIncludeRoot, setMarshalEmptyCollections, setNamespacePrefixMapper, setNamespaceSeparator, setValueWrapper, setWrapperAsArrayName, supportsMediaType, writeTo

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExcludeRootJSONProvider

      public ExcludeRootJSONProvider()
      Default constructor.
    • ExcludeRootJSONProvider

      @Inject public ExcludeRootJSONProvider(@Named("conf") org.apache.hadoop.conf.Configuration conf)
      Constructs a new ExcludeRootJSONProvider instance and initializes its ClassSerialisationConfig based on the provided application configuration.

      This constructor is designed for dependency injection. The Configuration object is injected (qualified with @Named("conf")) and used to create a ClassSerialisationConfig instance, which controls how classes are serialized to JSON (e.g., whether to include root elements).

      Parameters:
      conf - the application Configuration instance injected by the framework; used to initialize serialization settings
  • Method Details

    • isReadable

      public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Specified by:
      isReadable in interface javax.ws.rs.ext.MessageBodyReader<Object>
      Overrides:
      isReadable in class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
    • isWriteable

      public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Specified by:
      isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<Object>
      Overrides:
      isWriteable in class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
    • preReadFrom

      protected void preReadFrom(Class<Object> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders, javax.xml.bind.Unmarshaller unmarshaller) throws javax.xml.bind.JAXBException
      Overrides:
      preReadFrom in class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
      Throws:
      javax.xml.bind.JAXBException
    • preWriteTo

      protected void preWriteTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, javax.xml.bind.Marshaller marshaller) throws javax.xml.bind.JAXBException
      Overrides:
      preWriteTo in class org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
      Throws:
      javax.xml.bind.JAXBException