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