[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:
causality
is causing MGNLRESTCL-20 Cache browser can't authenticate sinc... Closed
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.

  • 5.4.8 ce-bundle pom
  • 5.4.8 changelog
  • 5.5 changelog ?

QA is done, can be closed after.

Generated at Mon Feb 12 10:42:24 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.