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

Spring RestClient returns an error when sending a MultipartFile "No serializer found for class sun.nio.ch.ChannelInputStream" #33726

Open
fachel opened this issue Oct 16, 2024 · 1 comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@fachel
Copy link

fachel commented Oct 16, 2024

I try send request via RestClient:

fun uploadFile(file: MultipartFile): MyDtoRs {
  val resource: Resource = file.resource
  val parts = LinkedMultiValueMap<String, Any>()
  parts.add("file", resource)
  val httpHeaders = HttpHeaders()
  httpHeaders.contentType = MediaType.MULTIPART_FORM_DATA
  val httpEntity = HttpEntity(parts, httpHeaders)
  val restClient = RestClient.create()

  return restClient.post()
            .uri("my/url")
            .body(httpEntity)
            .retrieve()
            .toEntity(MyDtoRs::class.java)
            .body!!
}

I get an error

"Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException:No serializer found for class sun.nio.ch.ChannelInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.http.HttpEntity["body"]->org.springframework.util.LinkedMultiValueMap["file"]->java.util.ArrayList[0]->org.springframework.web.multipart.MultipartFileResource["inputStream"])"

Spring Boot version 3.3.2
I found solve for RestTemplate:
How to send Multipart form data with restTemplate Spring-mvc - it work only for RestTemplate and not RestClient

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 16, 2024
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 17, 2024
@bclozel
Copy link
Member

bclozel commented Oct 23, 2024

Can you share a minimal sample?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

4 participants