Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
2a9a62d0
Commit
2a9a62d0
authored
May 10, 2017
by
Ryan Baxter
Committed by
GitHub
May 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1926 from TheSentinel454/issues_1676_wildcard_type_support
Add support for Wildcard Types in Feign Client. Fixes gh-1676
parents
377bccf1
189d926c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
SpringDecoder.java
...gframework/cloud/netflix/feign/support/SpringDecoder.java
+5
-3
SpringDecoderTests.java
...ringframework/cloud/netflix/feign/SpringDecoderTests.java
+24
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/support/SpringDecoder.java
View file @
2a9a62d0
...
...
@@ -22,6 +22,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.WildcardType
;
import
org.springframework.beans.factory.ObjectFactory
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
...
...
@@ -47,9 +48,10 @@ public class SpringDecoder implements Decoder {
}
@Override
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
FeignException
{
if
(
type
instanceof
Class
||
type
instanceof
ParameterizedType
)
{
public
Object
decode
(
final
Response
response
,
Type
type
)
throws
IOException
,
FeignException
{
if
(
type
instanceof
Class
||
type
instanceof
ParameterizedType
||
type
instanceof
WildcardType
)
{
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
HttpMessageConverterExtractor
<?>
extractor
=
new
HttpMessageConverterExtractor
(
type
,
this
.
messageConverters
.
getObject
().
getConverters
());
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/SpringDecoderTests.java
View file @
2a9a62d0
...
...
@@ -19,9 +19,11 @@ package org.springframework.cloud.netflix.feign;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -36,6 +38,7 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -109,6 +112,19 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
testWildcardTypeDecode
()
{
ResponseEntity
<?>
wildcard
=
testClient
().
getWildcard
();
assertNotNull
(
"wildcard was null"
,
wildcard
);
assertEquals
(
"wrong status code"
,
HttpStatus
.
OK
,
wildcard
.
getStatusCode
());
Object
wildcardBody
=
wildcard
.
getBody
();
assertNotNull
(
"wildcardBody was null"
,
wildcardBody
);
assertTrue
(
"wildcard not an instance of Map"
,
wildcardBody
instanceof
Map
);
Map
<
String
,
String
>
hello
=
(
Map
<
String
,
String
>)
wildcardBody
;
assertEquals
(
"first hello didn't match"
,
"wildcard"
,
hello
.
get
(
"message"
));
}
@Test
public
void
testResponseEntityVoid
()
{
ResponseEntity
<
Void
>
response
=
testClient
().
getHelloVoid
();
assertNotNull
(
"response was null"
,
response
);
...
...
@@ -156,6 +172,9 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hellonotfound"
)
ResponseEntity
<
String
>
getNotFound
();
@GetMapping
(
"/helloWildcard"
)
ResponseEntity
<?>
getWildcard
();
}
@Configuration
...
...
@@ -199,6 +218,11 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
((
String
)
null
);
}
@Override
public
ResponseEntity
<?>
getWildcard
()
{
return
ResponseEntity
.
ok
(
new
Hello
(
"wildcard"
));
}
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Application
.
class
)
.
properties
(
"spring.application.name=springdecodertest"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment