You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added support for custom POJO query param encoding (OpenFeign#667)
* Added support for custom param encoding
* Added ability to inherit @CustomParam annotation
* Updated class cast style to match rest of code
* Updated to use QueryMap for custom pojo query parameters
* Clarification in README of QueryMap POJO usage
* Removed unused line
* Updated custom POJO QueryMap test to prove that private fields can be used
* Removed no-longer-valid test endpoint
* Renamed tests to more accurately reflect their contents
* More test cleanup
* Modified QueryMap POJO encoding to use specified QueryMapEncoder (default implementation provided)
* Corrected typo in README.md
* Fixed merge conflict and typo in test name
Copy file name to clipboardExpand all lines: README.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -444,6 +444,35 @@ A Map parameter can be annotated with `QueryMap` to construct a query that uses
444
444
V find(@QueryMapMap<String, Object> queryMap);
445
445
```
446
446
447
+
This may also be used to generate the query parameters from a POJO object using a `QueryMapEncoder`.
448
+
449
+
```java
450
+
@RequestLine("GET /find")
451
+
V find(@QueryMapCustomPojo customPojo);
452
+
```
453
+
454
+
When used in this manner, without specifying a custom `QueryMapEncoder`, the query map will be generated using member variable names as query parameter names. The following POJO will generate query params of "/find?name={name}&number={number}" (order of included query parameters not guaranteed, and as usual, if any value is null, it will be left out).
455
+
456
+
```java
457
+
publicclassCustomPojo {
458
+
privatefinalString name;
459
+
privatefinalint number;
460
+
461
+
publicCustomPojo (Stringname, intnumber) {
462
+
this.name = name;
463
+
this.number = number;
464
+
}
465
+
}
466
+
```
467
+
468
+
To setup a custom `QueryMapEncoder`:
469
+
470
+
```java
471
+
MyApi myApi =Feign.builder()
472
+
.queryMapEncoder(newMyCustomQueryMapEncoder())
473
+
.target(MyApi.class, "https://api.hostname.com");
474
+
```
475
+
447
476
#### Static and Default Methods
448
477
Interfaces targeted by Feign may have static or default methods (if using Java 8+).
449
478
These allows Feign clients to contain logic that is not expressly defined by the underlying API.
0 commit comments