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

WebClient failed to write application/x-www-form-urlencoded [SPR-16055] #20604

Closed
spring-issuemaster opened this issue Oct 8, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Oct 8, 2017

Sola opened SPR-16055 and commented

According to
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java#L53-L54
and
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java#L53-L54

the FormHttpMessageWriter should accept any MultiValueMap<String,String>,
but the following test can't get passed

import org.junit.Assert
import org.junit.Test
import org.springframework.core.ResolvableType
import org.springframework.http.MediaType
import org.springframework.http.codec.FormHttpMessageWriter
import org.springframework.util.LinkedMultiValueMap
import org.springframework.util.MultiValueMap

class ResolvableTypeTest {

    @Test
    fun test() {
        val writer = FormHttpMessageWriter()
        Assert.assertTrue(
                writer.canWrite(
                        ResolvableType.forInstance(LinkedMultiValueMap<String, String>()),
                        MediaType.APPLICATION_FORM_URLENCODED
                )
        )
    }

    private val MULTIVALUE_TYPE = ResolvableType.forClassWithGenerics(MultiValueMap::class.java, String::class.java, String::class.java)

    @Test
    fun testSimulate() {
        Assert.assertTrue(
                MULTIVALUE_TYPE.isAssignableFrom(
                        ResolvableType.forInstance(
                                LinkedMultiValueMap<String, String>()
                        )
                )
        )
    }

}

// code above was written in Kotlin


Affects: 5.0 GA

Issue Links:

  • #20679 Multipart form data can no longer be sent with syncBody in WebTestClient
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 9, 2017

Sébastien Deleuze commented

SolaDev Using FormHttpMessageWriter requires indeed using fully resolved generic types, which is possible via ResolvableType.forClassWithGenerics or ParameterizedTypeReference. ResolvableType.forInstance won't work due to type erasure. Since ParameterizedTypeReference usage in Kotlin is not super idiomatic, I have introduced in WebClient several these Kotlin extensions that leverage Kotlin reified type parameters, could you try to use these ?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 12, 2017

Sébastien Deleuze commented

After more thoughts, we probably can relax type checks when unresolvable generics are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.