001/*002 * Copyright 2002-2020 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 at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * 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 and014 * limitations under the License.015 */016017package org.springframework.messaging.converter;018019import java.util.ArrayList;020import java.util.Collection;021import java.util.Collections;022import java.util.List;023024import org.apache.commons.logging.Log;025import org.apache.commons.logging.LogFactory;026027import org.springframework.messaging.Message;028import org.springframework.messaging.MessageHeaders;029import org.springframework.messaging.support.MessageBuilder;030import org.springframework.messaging.support.MessageHeaderAccessor;031import org.springframework.util.Assert;032import org.springframework.util.MimeType;033034/**035 * Abstract base class for {@link SmartMessageConverter} implementations including036 * support for common properties and a partial implementation of the conversion methods,037 * mainly to check if the converter supports the conversion based on the payload class038 * and MIME type.039 *040 * @author Rossen Stoyanchev041 * @author Sebastien Deleuze042 * @author Juergen Hoeller043 * @since 4.0044 */045public abstract class AbstractMessageConverter implements SmartMessageConverter {046047 protected final Log logger = LogFactory.getLog(getClass());048049 private final List<MimeType> supportedMimeTypes;050051 private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();052053 private boolean strictContentTypeMatch = false;054055 private Class<?> serializedPayloadClass = byte[].class;056057058 /**059 * Construct an {@code AbstractMessageConverter} supporting a single MIME type.060 * @param supportedMimeType the supported MIME type061 */062 protected AbstractMessageConverter(MimeType supportedMimeType) {063 Assert.notNull(supportedMimeType, "supportedMimeType is required");064 this.supportedMimeTypes = Collections.<MimeType>singletonList(supportedMimeType);065 }066067 /**068 * Construct an {@code AbstractMessageConverter} supporting multiple MIME types.069 * @param supportedMimeTypes the supported MIME types070 */071 protected AbstractMessageConverter(Collection<MimeType> supportedMimeTypes) {072 Assert.notNull(supportedMimeTypes, "supportedMimeTypes must not be null");073 this.supportedMimeTypes = new ArrayList<MimeType>(supportedMimeTypes);074 }075