|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -703,6 +703,27 @@ public void resolveArgumentTypeVariableWithGenericInterface() throws Exception {
|
703 | 703 |
|
704 | 704 | RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
|
705 | 705 |
|
| 706 | + assertTrue(processor.supportsParameter(methodParameter)); |
| 707 | + String value = (String) processor.readWithMessageConverters( |
| 708 | + this.request, methodParameter, methodParameter.getGenericParameterType()); |
| 709 | + assertEquals("foo", value); |
| 710 | + } |
| 711 | + |
| 712 | + @Test // gh-24127 |
| 713 | + public void resolveArgumentTypeVariableWithGenericInterfaceAndSubclass() throws Exception { |
| 714 | + this.servletRequest.setContent("\"foo\"".getBytes("UTF-8")); |
| 715 | + this.servletRequest.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); |
| 716 | + |
| 717 | + Method method = SubControllerImplementingInterface.class.getMethod("handle", Object.class); |
| 718 | + HandlerMethod handlerMethod = new HandlerMethod(new SubControllerImplementingInterface(), method); |
| 719 | + MethodParameter methodParameter = handlerMethod.getMethodParameters()[0]; |
| 720 | + |
| 721 | + List<HttpMessageConverter<?>> converters = new ArrayList<>(); |
| 722 | + converters.add(new MappingJackson2HttpMessageConverter()); |
| 723 | + |
| 724 | + RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters); |
| 725 | + |
| 726 | + assertTrue(processor.supportsParameter(methodParameter)); |
706 | 727 | String value = (String) processor.readWithMessageConverters(
|
707 | 728 | this.request, methodParameter, methodParameter.getGenericParameterType());
|
708 | 729 | assertEquals("foo", value);
|
@@ -1055,4 +1076,13 @@ default A handle(@RequestBody A arg) {
|
1055 | 1076 | static class MyControllerImplementingInterface implements MappingInterface<String> {
|
1056 | 1077 | }
|
1057 | 1078 |
|
| 1079 | + |
| 1080 | + static class SubControllerImplementingInterface extends MyControllerImplementingInterface { |
| 1081 | + |
| 1082 | + @Override |
| 1083 | + public String handle(String arg) { |
| 1084 | + return arg; |
| 1085 | + } |
| 1086 | + } |
| 1087 | + |
1058 | 1088 | }
|
0 commit comments