001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.messaging.converter; 018 019import org.springframework.messaging.Message; 020import org.springframework.messaging.MessageHeaders; 021 022/** 023 * An extended {@link MessageConverter} SPI with conversion hint support. 024 * 025 * <p>In case of a conversion hint being provided, the framework will call 026 * these extended methods if a converter implements this interface, instead 027 * of calling the regular {@code fromMessage} / {@code toMessage} variants. 028 * 029 * @author Juergen Hoeller 030 * @since 4.2.1 031 */ 032public interface SmartMessageConverter extends MessageConverter { 033 034 /** 035 * A variant of {@link #fromMessage(Message, Class)} which takes an extra 036 * conversion context as an argument, allowing to take e.g. annotations 037 * on a payload parameter into account. 038 * @param message the input message 039 * @param targetClass the target class for the conversion 040 * @param conversionHint an extra object passed to the {@link MessageConverter}, 041 * e.g. the associated {@code MethodParameter} (may be {@code null}} 042 * @return the result of the conversion, or {@code null} if the converter cannot 043 * perform the conversion 044 * @see #fromMessage(Message, Class) 045 */ 046 Object fromMessage(Message<?> message, Class<?> targetClass, Object conversionHint); 047 048 /** 049 * A variant of {@link #toMessage(Object, MessageHeaders)} which takes an extra 050 * conversion context as an argument, allowing to take e.g. annotations 051 * on a return type into account. 052 * @param payload the Object to convert 053 * @param headers optional headers for the message (may be {@code null}) 054 * @param conversionHint an extra object passed to the {@link MessageConverter}, 055 * e.g. the associated {@code MethodParameter} (may be {@code null}} 056 * @return the new message, or {@code null} if the converter does not support the 057 * Object type or the target media type 058 * @see #toMessage(Object, MessageHeaders) 059 */ 060 Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint); 061 062}