org.springframework.amqp.support.converter.SerializerMessageConverter Maven / Gradle / Ivy
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.amqp.support.converter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.io.UnsupportedEncodingException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.ConfigurableObjectInputStream;
import org.springframework.core.NestedIOException;
import org.springframework.core.serializer.DefaultDeserializer;
import org.springframework.core.serializer.DefaultSerializer;
import org.springframework.core.serializer.Deserializer;
import org.springframework.core.serializer.Serializer;
/**
* Implementation of {@link MessageConverter} that can work with Strings or native objects
* of any kind via the {@link Serializer} and {@link Deserializer} abstractions in Spring.
* The {@link #toMessage(Object, MessageProperties)} method simply checks the type of the
* provided instance while the {@link #fromMessage(Message)} method relies upon the
* {@link MessageProperties#getContentType() content-type} of the provided Message.
*
* If a {@link DefaultDeserializer} is configured (default),
* the {@link #setWhiteListPatterns(java.util.List) white list patterns} will be applied
* (if configured); for all other deserializers, the deserializer is responsible for
* checking classes, if necessary.
*
* @author Dave Syer
* @author Gary Russell
*/
public class SerializerMessageConverter extends WhiteListDeserializingMessageConverter {
public static final String DEFAULT_CHARSET = "UTF-8";
private volatile String defaultCharset = DEFAULT_CHARSET;
private volatile Serializer