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.handler.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import org.springframework.core.annotation.AliasFor; 026import org.springframework.messaging.converter.MessageConverter; 027 028/** 029 * Annotation that binds a method parameter to the payload of a message. Can also 030 * be used to associate a payload to a method invocation. The payload may be passed 031 * through a {@link MessageConverter} to convert it from serialized form with a 032 * specific MIME type to an Object matching the target method parameter. 033 * 034 * @author Rossen Stoyanchev 035 * @author Sam Brannen 036 * @since 4.0 037 */ 038@Target({ElementType.PARAMETER, ElementType.METHOD}) 039@Retention(RetentionPolicy.RUNTIME) 040@Documented 041public @interface Payload { 042 043 /** 044 * Alias for {@link #expression}. 045 */ 046 @AliasFor("expression") 047 String value() default ""; 048 049 /** 050 * A SpEL expression to be evaluated against the payload object as the root context. 051 * <p>This attribute may or may not be supported depending on whether the message being 052 * handled contains a non-primitive Object as its payload or is in serialized form and 053 * requires message conversion. 054 * <p>When processing STOMP over WebSocket messages this attribute is not supported. 055 * @since 4.2 056 */ 057 @AliasFor("value") 058 String expression() default ""; 059 060 /** 061 * Whether payload content is required. 062 * <p>Default is {@code true}, leading to an exception if there is no payload. Switch 063 * to {@code false} to have {@code null} passed when there is no payload. 064 */ 065 boolean required() default true; 066 067}