001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nicolas Chapurlat <nchapurlat@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.core.io.registry; 019 020import java.lang.reflect.Type; 021 022import javax.inject.Inject; 023import javax.ws.rs.core.MediaType; 024 025import org.nuxeo.ecm.core.io.registry.context.RenderingContext; 026import org.nuxeo.ecm.core.io.registry.reflect.Setup; 027import org.nuxeo.ecm.core.io.registry.reflect.Supports; 028 029/** 030 * Interface of Java type converter. 031 * <p> 032 * You must add {@link Setup} annotation to every class implementing this interface. You should add {@link Supports} 033 * annotation to define supported mimetype. You can add {@link Inject} annotation to your properties to get current 034 * {@link RenderingContext} or any Nuxeo service. 035 * </p> 036 * <p> 037 * To get an instance of this class with injected properties, call 038 * {@link MarshallerRegistry#getInstance(RenderingContext, Class)}. 039 * </p> 040 * 041 * @param <EntityType> The managed Java type. 042 * @since 7.2 043 */ 044public interface Marshaller<EntityType> { 045 046 /** 047 * Checks if this marshaller can handle the marshalling request. 048 * <p> 049 * Please note it's useless to check that clazz is an instance of EntityType or if generic type and entity type are 050 * compatible (unlike JAX-RS which just checks the clazz, not the generic type). It's also useless to check 051 * {@link Supports} is compatible with mediatype. This is already done by the {@link MarshallerRegistry} 052 * </p> 053 * <p> 054 * This method implementation can use injected properties. So you can check the current {@link RenderingContext} to 055 * accept or reject a marshalling request. 056 * </p> 057 * 058 * @param clazz The type to marshall. 059 * @param genericType The generic type to marshall. 060 * @param mediatype The managed mimetype. 061 * @return true if this converter handle the request, false otherwise. 062 * @since 7.2 063 */ 064 public boolean accept(Class<?> clazz, Type genericType, MediaType mediatype); 065 066}