001/* 002 * Copyright 2002-2018 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.codec.json; 018 019import com.fasterxml.jackson.databind.ObjectMapper; 020import com.fasterxml.jackson.dataformat.smile.SmileFactory; 021 022import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 023import org.springframework.util.Assert; 024import org.springframework.util.MimeType; 025 026/** 027 * Decode a byte stream into Smile and convert to Object's with Jackson 2.9, 028 * leveraging non-blocking parsing. 029 * 030 * @author Sebastien Deleuze 031 * @author Rossen Stoyanchev 032 * @since 5.0 033 * @see Jackson2JsonEncoder 034 */ 035public class Jackson2SmileDecoder extends AbstractJackson2Decoder { 036 037 private static final MimeType[] DEFAULT_SMILE_MIME_TYPES = new MimeType[] { 038 new MimeType("application", "x-jackson-smile"), 039 new MimeType("application", "*+x-jackson-smile")}; 040 041 042 public Jackson2SmileDecoder() { 043 this(Jackson2ObjectMapperBuilder.smile().build(), DEFAULT_SMILE_MIME_TYPES); 044 } 045 046 public Jackson2SmileDecoder(ObjectMapper mapper, MimeType... mimeTypes) { 047 super(mapper, mimeTypes); 048 Assert.isAssignable(SmileFactory.class, mapper.getFactory().getClass()); 049 } 050 051}