@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2019 the original author or authors .
* Copyright 2002 - 2020 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -19,12 +19,18 @@ package org.springframework.http.codec.json;
import java.lang.annotation.Annotation ;
import java.lang.annotation.Annotation ;
import java.lang.reflect.Type ;
import java.lang.reflect.Type ;
import java.nio.charset.StandardCharsets ;
import java.nio.charset.StandardCharsets ;
import java.nio.charset.Charset ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.EnumSet ;
import java.util.HashMap ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
import com.fasterxml.jackson.annotation.JsonView ;
import com.fasterxml.jackson.annotation.JsonView ;
import com.fasterxml.jackson.core.JsonEncoding ;
import com.fasterxml.jackson.databind.JavaType ;
import com.fasterxml.jackson.databind.JavaType ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.fasterxml.jackson.databind.type.TypeFactory ;
import com.fasterxml.jackson.databind.type.TypeFactory ;
@ -64,6 +70,9 @@ public abstract class Jackson2CodecSupport {
new MimeType ( "application" , "json" , StandardCharsets . UTF_8 ) ,
new MimeType ( "application" , "json" , StandardCharsets . UTF_8 ) ,
new MimeType ( "application" , "*+json" , StandardCharsets . UTF_8 ) ) ) ;
new MimeType ( "application" , "*+json" , StandardCharsets . UTF_8 ) ) ) ;
private static final Map < String , JsonEncoding > ENCODINGS = jsonEncodings ( ) ;
protected final Log logger = HttpLogging . forLogName ( getClass ( ) ) ;
protected final Log logger = HttpLogging . forLogName ( getClass ( ) ) ;
@ -96,7 +105,17 @@ public abstract class Jackson2CodecSupport {
protected boolean supportsMimeType ( @Nullable MimeType mimeType ) {
protected boolean supportsMimeType ( @Nullable MimeType mimeType ) {
return ( mimeType = = null | | this . mimeTypes . stream ( ) . anyMatch ( m - > m . isCompatibleWith ( mimeType ) ) ) ;
if ( mimeType = = null ) {
return true ;
}
else if ( this . mimeTypes . stream ( ) . noneMatch ( m - > m . isCompatibleWith ( mimeType ) ) ) {
return false ;
}
else if ( mimeType . getCharset ( ) ! = null ) {
Charset charset = mimeType . getCharset ( ) ;
return ENCODINGS . containsKey ( charset . name ( ) ) ;
}
return true ;
}
}
protected JavaType getJavaType ( Type type , @Nullable Class < ? > contextClass ) {
protected JavaType getJavaType ( Type type , @Nullable Class < ? > contextClass ) {
@ -125,4 +144,10 @@ public abstract class Jackson2CodecSupport {
@Nullable
@Nullable
protected abstract < A extends Annotation > A getAnnotation ( MethodParameter parameter , Class < A > annotType ) ;
protected abstract < A extends Annotation > A getAnnotation ( MethodParameter parameter , Class < A > annotType ) ;
private static Map < String , JsonEncoding > jsonEncodings ( ) {
return EnumSet . allOf ( JsonEncoding . class ) . stream ( )
. collect ( Collectors . toMap ( JsonEncoding : : getJavaName , Function . identity ( ) ) ) ;
}
}
}