001/*
002 * Copyright 2002-2017 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.http.converter.json;
018
019import java.io.IOException;
020import java.io.InputStream;
021
022import org.springframework.http.HttpHeaders;
023import org.springframework.http.HttpInputMessage;
024import org.springframework.lang.Nullable;
025
026/**
027 * {@link HttpInputMessage} that can eventually stores a Jackson view that will be used
028 * to deserialize the message.
029 *
030 * @author Sebastien Deleuze
031 * @since 4.2
032 */
033public class MappingJacksonInputMessage implements HttpInputMessage {
034
035        private final InputStream body;
036
037        private final HttpHeaders headers;
038
039        @Nullable
040        private Class<?> deserializationView;
041
042
043        public MappingJacksonInputMessage(InputStream body, HttpHeaders headers) {
044                this.body = body;
045                this.headers = headers;
046        }
047
048        public MappingJacksonInputMessage(InputStream body, HttpHeaders headers, Class<?> deserializationView) {
049                this(body, headers);
050                this.deserializationView = deserializationView;
051        }
052
053
054        @Override
055        public InputStream getBody() throws IOException {
056                return this.body;
057        }
058
059        @Override
060        public HttpHeaders getHeaders() {
061                return this.headers;
062        }
063
064        public void setDeserializationView(@Nullable Class<?> deserializationView) {
065                this.deserializationView = deserializationView;
066        }
067
068        @Nullable
069        public Class<?> getDeserializationView() {
070                return this.deserializationView;
071        }
072
073}