1 /*
2  * Copyright 2002-2017 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 module hunt.stomp.converter.MessageConverter;
18 
19 
20 import hunt.stomp.Message;
21 import hunt.stomp.MessageHeaders;
22 
23 /**
24  * A converter to turn the payload of a {@link Message} from serialized form to a typed
25  * Object and vice versa. The {@link MessageHeaders#CONTENT_TYPE} message header may be
26  * used to specify the media type of the message content.
27  *
28  * @author Mark Fisher
29  * @author Rossen Stoyanchev
30  * @since 4.0
31  */
32 interface MessageConverter {
33 
34 	/**
35 	 * Convert the payload of a {@link Message} from a serialized form to a typed Object
36 	 * of the specified target class. The {@link MessageHeaders#CONTENT_TYPE} header
37 	 * should indicate the MIME type to convert from.
38 	 * <p>If the converter does not support the specified media type or cannot perform
39 	 * the conversion, it should return {@code null}.
40 	 * @param message the input message
41 	 * @param targetClass the target class for the conversion
42 	 * @return the result of the conversion, or {@code null} if the converter cannot
43 	 * perform the conversion
44 	 */	
45 	Object fromMessage(MessageBase message, TypeInfo targetClass);
46 
47 	/**
48 	 * Create a {@link Message} whose payload is the result of converting the given
49 	 * payload Object to serialized form. The optional {@link MessageHeaders} parameter
50 	 * may contain a {@link MessageHeaders#CONTENT_TYPE} header to specify the target
51 	 * media type for the conversion and it may contain additional headers to be added
52 	 * to the message.
53 	 * <p>If the converter does not support the specified media type or cannot perform
54 	 * the conversion, it should return {@code null}.
55 	 * @param payload the Object to convert
56 	 * @param headers optional headers for the message (may be {@code null})
57 	 * @return the new message, or {@code null} if the converter does not support the
58 	 * Object type or the target media type
59 	 */	
60 	MessageBase toMessage(Object payload, MessageHeaders headers);
61 
62 }