[MGNLRESTCL-19] Allow to register custom parameter converters Created: 22/Jun/16 Updated: 17/Aug/16 Resolved: 27/Jun/16 |
|
| Status: | Closed |
| Project: | REST Client |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.0.8 |
| Type: | Improvement | Priority: | Neutral |
| Reporter: | Jaroslav Simak | Assignee: | Jaroslav Simak |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Template: |
|
||||||||
| Acceptance criteria: |
Empty
|
||||||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||
| Documentation update required: |
Yes
|
||||||||
| Date of First Response: | |||||||||
| Sprint: | Kromeriz 50 | ||||||||
| Story Points: | 1 | ||||||||
| Comments |
| Comment by Jaroslav Simak [ 22/Jun/16 ] |
|
Here is a sample code of a converter that can be used during QA: import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import org.apache.commons.lang3.StringUtils;
/**
* Converts collection of strings to one string using {@code ,} as a separator character.
*/
public class CollectionParamConverterProvider implements ParamConverterProvider {
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (Collection.class.isAssignableFrom(rawType)) {
return (ParamConverter<T>) new ParamConverter<Collection<String>>() {
@Override
public Collection<String> fromString(String value) {
return Arrays.asList(StringUtils.split(value, ","));
}
@Override
public String toString(Collection<String> value) {
return StringUtils.join(value, ",");
}
};
}
return null;
}
}
|
| Comment by Evzen Fochr [ 29/Jun/16 ] |
|
Add to changelogs and bundle pom.
QA is done, can be closed after. |