@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2022 the original author or authors .
* Copyright 2002 - 2023 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 .
@ -24,8 +24,11 @@ import java.util.ArrayList;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Optional ;
import com.fasterxml.jackson.annotation.JsonFilter ;
import com.fasterxml.jackson.annotation.JsonFilter ;
import com.fasterxml.jackson.annotation.JsonSubTypes ;
import com.fasterxml.jackson.annotation.JsonTypeInfo ;
import com.fasterxml.jackson.annotation.JsonView ;
import com.fasterxml.jackson.annotation.JsonView ;
import com.fasterxml.jackson.databind.DeserializationFeature ;
import com.fasterxml.jackson.databind.DeserializationFeature ;
import com.fasterxml.jackson.databind.JavaType ;
import com.fasterxml.jackson.databind.JavaType ;
@ -345,6 +348,18 @@ public class MappingJackson2HttpMessageConverterTests {
JSONAssert . assertEquals ( body , outputMessage . getBodyAsString ( StandardCharsets . UTF_8 ) , true ) ;
JSONAssert . assertEquals ( body , outputMessage . getBodyAsString ( StandardCharsets . UTF_8 ) , true ) ;
}
}
// gh-24498
@Test
public void writeOptional ( ) throws IOException {
ParameterizedTypeReference < Optional < MyParent > > optionalParent = new ParameterizedTypeReference < > ( ) { } ;
Optional < MyParent > result = Optional . of ( new Impl1 ( ) ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
converter . write ( result , optionalParent . getType ( ) , MediaType . APPLICATION_JSON , outputMessage ) ;
assertThat ( outputMessage . getBodyAsString ( StandardCharsets . UTF_8 ) )
. contains ( "@type" ) ;
}
@Test
@Test
public void prettyPrint ( ) throws Exception {
public void prettyPrint ( ) throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
@ -773,6 +788,18 @@ public class MappingJackson2HttpMessageConverterTests {
}
}
}
}
@JsonTypeInfo ( use = JsonTypeInfo . Id . NAME )
@JsonSubTypes ( value = { @JsonSubTypes.Type ( value = Impl1 . class ) ,
@JsonSubTypes.Type ( value = Impl2 . class ) } )
public static interface MyParent {
}
public static class Impl1 implements MyParent {
}
public static class Impl2 implements MyParent {
}
private static class MappingJackson2HttpMessageConverterWithCustomization extends MappingJackson2HttpMessageConverter {
private static class MappingJackson2HttpMessageConverterWithCustomization extends MappingJackson2HttpMessageConverter {
@Override
@Override