Skip to content

Attempt to submit a form using Map<String, String> results in EncodeException #2827

@gkresic

Description

@gkresic

One of our Feign clients looked like:

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "authClient", url = "${auth.url}", configuration = AuthClient.Configuration.class)
public interface AuthClient {

    @PostMapping(value = "/oauth2/token", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    AuthResponse getAccessToken(@RequestBody Map<String, ?> request);

}

This works. However, changing request type from Map<String, ?> to Map<String, String> causes Feign to fail with:

feign.codec.EncodeException Unable to make field transient java.util.HashMap$Node[] java.util.HashMap.table accessible: module java.base does not "opens java.util" to unnamed module @531be3c5

During my investigation, I learned about Feign's close relationship with Map<String, ?> via feign.codec.Encoder#MAP_STRING_WILDCARD, but even if this is not a bug, but a design choice, it just seems like it should be handled more gracefully.

io.github.openfeign:feign-core:12.5
io.github.openfeign:feign-okhttp:13.2.1
io.github.openfeign.form:feign-form:3.8.0
io.github.openfeign.form:feign-form-spring:3.8.0
io.github.openfeign:feign-slf4j:12.5
org.springframework.cloud:spring-cloud-starter-openfeign:4.0.6
OpenJDK 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions