4848import org .springframework .core .ParameterizedTypeReference ;
4949import org .springframework .core .ResolvableType ;
5050import org .springframework .http .MediaType ;
51+ import org .springframework .http .ResponseEntity ;
5152import org .springframework .http .converter .HttpMessageNotReadableException ;
5253import org .springframework .web .testfixture .http .MockHttpInputMessage ;
5354import org .springframework .web .testfixture .http .MockHttpOutputMessage ;
@@ -67,6 +68,8 @@ class JacksonJsonHttpMessageConverterTests {
6768
6869 private JacksonJsonHttpMessageConverter converter = new JacksonJsonHttpMessageConverter ();
6970
71+ private final ResolvableType unresolvableType = ResolvableType .forClass (ResponseEntity .class ).getNested (2 );
72+
7073
7174 @ Test
7275 void canRead () {
@@ -75,6 +78,7 @@ void canRead() {
7578 assertThat (this .converter .canRead (MyBean .class , new MediaType ("application" , "json" , StandardCharsets .UTF_8 ))).isTrue ();
7679 assertThat (this .converter .canRead (MyBean .class , new MediaType ("application" , "json" , StandardCharsets .US_ASCII ))).isTrue ();
7780 assertThat (this .converter .canRead (MyBean .class , new MediaType ("application" , "json" , StandardCharsets .ISO_8859_1 ))).isTrue ();
81+ assertThat (this .converter .canRead (this .unresolvableType , MediaType .APPLICATION_JSON )).isTrue ();
7882 }
7983
8084 @ Test
@@ -173,6 +177,29 @@ void readUntyped() throws IOException {
173177 assertThat (result ).containsEntry ("bool" , Boolean .TRUE );
174178 assertThat (result ).containsEntry ("bytes" , "AQI=" );
175179 }
180+ @ Test
181+ @ SuppressWarnings ("unchecked" )
182+ void readUnresolable () throws IOException {
183+ String body = "{" +
184+ "\" bytes\" :\" AQI=\" ," +
185+ "\" array\" :[\" Foo\" ,\" Bar\" ]," +
186+ "\" number\" :42," +
187+ "\" string\" :\" Foo\" ," +
188+ "\" bool\" :true," +
189+ "\" fraction\" :42.0}" ;
190+ MockHttpInputMessage inputMessage = new MockHttpInputMessage (body .getBytes (StandardCharsets .UTF_8 ));
191+ inputMessage .getHeaders ().setContentType (new MediaType ("application" , "json" ));
192+ HashMap <String , Object > result = (HashMap <String , Object >) this .converter .read (this .unresolvableType , inputMessage , null );
193+ assertThat (result ).containsEntry ("string" , "Foo" );
194+ assertThat (result ).containsEntry ("number" , 42 );
195+ assertThat ((Double ) result .get ("fraction" )).isCloseTo (42D , within (0D ));
196+ List <String > array = new ArrayList <>();
197+ array .add ("Foo" );
198+ array .add ("Bar" );
199+ assertThat (result ).containsEntry ("array" , array );
200+ assertThat (result ).containsEntry ("bool" , Boolean .TRUE );
201+ assertThat (result ).containsEntry ("bytes" , "AQI=" );
202+ }
176203
177204 @ Test
178205 void write () throws IOException {
0 commit comments