Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow QueryMapEncoder accept null value #2086

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/java/feign/querymap/BeanQueryMapEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class BeanQueryMapEncoder implements QueryMapEncoder {

@Override
public Map<String, Object> encode(Object object) throws EncodeException {
if (object == null) {
return Collections.emptyMap();
}
try {
ObjectParamMetadata metadata = getMetadata(object.getClass());
Map<String, Object> propertyNameToValue = new HashMap<String, Object>();
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/feign/querymap/FieldQueryMapEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class FieldQueryMapEncoder implements QueryMapEncoder {

@Override
public Map<String, Object> encode(Object object) throws EncodeException {
if (object == null) {
return Collections.emptyMap();
}
ObjectParamMetadata metadata =
classToMetadata.computeIfAbsent(object.getClass(), ObjectParamMetadata::parseObjectType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -34,6 +35,11 @@ public class BeanQueryMapEncoderTest {

private final QueryMapEncoder encoder = new BeanQueryMapEncoder();

@Test
public void testDefaultEncoder_acceptNullValue() {
assertEquals("Empty map should be returned", Collections.EMPTY_MAP, encoder.encode(null));
}

@Test
public void testDefaultEncoder_normalClassWithValues() {
Map<String, Object> expected = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -33,6 +34,11 @@ public class FieldQueryMapEncoderTest {

private final QueryMapEncoder encoder = new FieldQueryMapEncoder();

@Test
public void testDefaultEncoder_acceptNullValue() {
assertEquals("Empty map should be returned", Collections.EMPTY_MAP, encoder.encode(null));
}

@Test
public void testDefaultEncoder_normalClassWithValues() {
final Map<String, Object> expected = new HashMap<>();
Expand Down