From 71afc0761f6a4333cf614cda91df4272d137afbe Mon Sep 17 00:00:00 2001 From: Witalij Berdinskich Date: Mon, 20 Dec 2021 11:23:53 +0200 Subject: [PATCH] Deprecate QueryMap.encode, remove processing of the "encode" parameter --- core/src/main/java/feign/Contract.java | 1 - core/src/main/java/feign/MethodMetadata.java | 10 ---- core/src/main/java/feign/QueryMap.java | 10 +++- core/src/main/java/feign/ReflectiveFeign.java | 13 ++--- .../test/java/feign/DefaultContractTest.java | 54 ------------------- core/src/test/java/feign/FeignTest.java | 7 +-- 6 files changed, 14 insertions(+), 81 deletions(-) diff --git a/core/src/main/java/feign/Contract.java b/core/src/main/java/feign/Contract.java index 3d653ca9c..091c72ff1 100644 --- a/core/src/main/java/feign/Contract.java +++ b/core/src/main/java/feign/Contract.java @@ -308,7 +308,6 @@ public Default() { checkState(data.queryMapIndex() == null, "QueryMap annotation was present on multiple parameters."); data.queryMapIndex(paramIndex); - data.queryMapEncoded(queryMap.encoded()); }); super.registerParameterAnnotation(HeaderMap.class, (queryMap, data, paramIndex) -> { checkState(data.headerMapIndex() == null, diff --git a/core/src/main/java/feign/MethodMetadata.java b/core/src/main/java/feign/MethodMetadata.java index b4370764d..f5fcc964a 100644 --- a/core/src/main/java/feign/MethodMetadata.java +++ b/core/src/main/java/feign/MethodMetadata.java @@ -29,7 +29,6 @@ public final class MethodMetadata implements Serializable { private Integer bodyIndex; private Integer headerMapIndex; private Integer queryMapIndex; - private boolean queryMapEncoded; private boolean alwaysEncodeBody; private transient Type bodyType; private final RequestTemplate template = new RequestTemplate(); @@ -110,15 +109,6 @@ public MethodMetadata queryMapIndex(Integer queryMapIndex) { return this; } - public boolean queryMapEncoded() { - return queryMapEncoded; - } - - public MethodMetadata queryMapEncoded(boolean queryMapEncoded) { - this.queryMapEncoded = queryMapEncoded; - return this; - } - @Experimental public boolean alwaysEncodeBody() { return alwaysEncodeBody; diff --git a/core/src/main/java/feign/QueryMap.java b/core/src/main/java/feign/QueryMap.java index 6515f21d7..c590bf7a9 100644 --- a/core/src/main/java/feign/QueryMap.java +++ b/core/src/main/java/feign/QueryMap.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -53,15 +53,21 @@ * Once this conversion is applied, the query keys and resulting String values follow the same * contract as if they were set using {@link RequestTemplate#query(String, String...)}. */ -@SuppressWarnings("deprecation") @Retention(RUNTIME) @java.lang.annotation.Target(PARAMETER) public @interface QueryMap { /** * Specifies whether parameter names and values are already encoded. + *

+ * Deprecation: there are two options + *

* * @see Param#encoded + * @deprecated */ boolean encoded() default false; } diff --git a/core/src/main/java/feign/ReflectiveFeign.java b/core/src/main/java/feign/ReflectiveFeign.java index 426f7cf96..344b76572 100644 --- a/core/src/main/java/feign/ReflectiveFeign.java +++ b/core/src/main/java/feign/ReflectiveFeign.java @@ -302,27 +302,22 @@ private RequestTemplate addQueryMapQueryParameters(Map queryMap, for (Entry currEntry : queryMap.entrySet()) { Collection values = new ArrayList(); - boolean encoded = metadata.queryMapEncoded(); Object currValue = currEntry.getValue(); if (currValue instanceof Iterable) { Iterator iter = ((Iterable) currValue).iterator(); while (iter.hasNext()) { Object nextObject = iter.next(); - values.add(nextObject == null ? null - : encoded ? nextObject.toString() - : UriUtils.encode(nextObject.toString())); + values.add(nextObject == null ? null : UriUtils.encode(nextObject.toString())); } } else if (currValue instanceof Object[]) { for (Object value : (Object[]) currValue) { - values.add(value == null ? null - : encoded ? value.toString() : UriUtils.encode(value.toString())); + values.add(value == null ? null : UriUtils.encode(value.toString())); } } else { - values.add(currValue == null ? null - : encoded ? currValue.toString() : UriUtils.encode(currValue.toString())); + values.add(currValue == null ? null : UriUtils.encode(currValue.toString())); } - mutable.query(encoded ? currEntry.getKey() : UriUtils.encode(currEntry.getKey()), values); + mutable.query(UriUtils.encode(currEntry.getKey()), values); } return mutable; } diff --git a/core/src/test/java/feign/DefaultContractTest.java b/core/src/test/java/feign/DefaultContractTest.java index 259c24227..fdf894db4 100644 --- a/core/src/test/java/feign/DefaultContractTest.java +++ b/core/src/test/java/feign/DefaultContractTest.java @@ -326,30 +326,6 @@ public void queryMap() throws Exception { assertThat(md.queryMapIndex()).isEqualTo(0); } - @Test - public void queryMapEncodedDefault() throws Exception { - final MethodMetadata md = - parseAndValidateMetadata(QueryMapTestInterface.class, "queryMap", Map.class); - - assertThat(md.queryMapEncoded()).isFalse(); - } - - @Test - public void queryMapEncodedTrue() throws Exception { - final MethodMetadata md = - parseAndValidateMetadata(QueryMapTestInterface.class, "queryMapEncoded", Map.class); - - assertThat(md.queryMapEncoded()).isTrue(); - } - - @Test - public void queryMapEncodedFalse() throws Exception { - final MethodMetadata md = - parseAndValidateMetadata(QueryMapTestInterface.class, "queryMapNotEncoded", Map.class); - - assertThat(md.queryMapEncoded()).isFalse(); - } - @Test public void queryMapMapSubclass() throws Exception { final MethodMetadata md = @@ -388,24 +364,6 @@ public void queryMapPojoObject() throws Exception { assertThat(md.queryMapIndex()).isEqualTo(0); } - @Test - public void queryMapPojoObjectEncoded() throws Exception { - final MethodMetadata md = - parseAndValidateMetadata(QueryMapTestInterface.class, "pojoObjectEncoded", Object.class); - - assertThat(md.queryMapIndex()).isEqualTo(0); - assertThat(md.queryMapEncoded()).isTrue(); - } - - @Test - public void queryMapPojoObjectNotEncoded() throws Exception { - final MethodMetadata md = - parseAndValidateMetadata(QueryMapTestInterface.class, "pojoObjectNotEncoded", Object.class); - - assertThat(md.queryMapIndex()).isEqualTo(0); - assertThat(md.queryMapEncoded()).isFalse(); - } - @Test public void slashAreEncodedWhenNeeded() throws Exception { MethodMetadata md = parseAndValidateMetadata(SlashNeedToBeEncoded.class, @@ -609,21 +567,9 @@ interface QueryMapTestInterface { @RequestLine("POST /") void queryMapMapSubclass(@QueryMap SortedMap queryMap); - @RequestLine("POST /") - void queryMapEncoded(@QueryMap(encoded = true) Map queryMap); - - @RequestLine("POST /") - void queryMapNotEncoded(@QueryMap(encoded = false) Map queryMap); - @RequestLine("POST /") void pojoObject(@QueryMap Object object); - @RequestLine("POST /") - void pojoObjectEncoded(@QueryMap(encoded = true) Object object); - - @RequestLine("POST /") - void pojoObjectNotEncoded(@QueryMap(encoded = false) Object object); - // invalid @RequestLine("POST /") void multipleQueryMap(@QueryMap Map mapOne, diff --git a/core/src/test/java/feign/FeignTest.java b/core/src/test/java/feign/FeignTest.java index 8aa94a357..fba600d97 100644 --- a/core/src/test/java/feign/FeignTest.java +++ b/core/src/test/java/feign/FeignTest.java @@ -365,14 +365,14 @@ public void queryMapValueStartingWithBrace() throws Exception { server.enqueue(new MockResponse()); queryMap = new LinkedHashMap(); queryMap.put("name", "%7Balice"); - api.queryMapEncoded(queryMap); + api.queryMap(queryMap); assertThat(server.takeRequest()) .hasPath("/?name=%7Balice"); server.enqueue(new MockResponse()); queryMap = new LinkedHashMap(); queryMap.put("%7Bname", "%7Balice"); - api.queryMapEncoded(queryMap); + api.queryMap(queryMap); assertThat(server.takeRequest()) .hasPath("/?%7Bname=%7Balice"); } @@ -971,9 +971,6 @@ void form( @RequestLine("GET /") void queryMap(@QueryMap Map queryMap); - @RequestLine("GET /") - void queryMapEncoded(@QueryMap(encoded = true) Map queryMap); - @RequestLine("GET /?name={name}") void queryMapWithQueryParams(@Param("name") String name, @QueryMap Map queryMap);