question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassCastException Thrown when referring json file in request body with content type "multipart/form-data"

See original GitHub issue

Issue:

With content-type:"multipart/form-data" getting java.lang.ClassCastException when referring json file for additional payload in Request Body apart from "files": [ "file:media/test.wav" ]

Request step:

{
  "name": "save_config",
  "url": "/config",
  "operation": "POST",
  "request": {
    "headers": "${JSON.FILE:standard_headers_media.json}",
    "body": {
      "files": [
        "file:media/test.wav"
      ],
      "metadata": "${JSON.FILE:metadata.json}"
    }
  },
  "assertions": {
    "status": 201,
    "headers": {
      "${correlationId.header}": "$NOT.NULL"
    }
  }
}

metadata.json

{
  "name": "name",
  "fileName": "test.wav",
  "location": "location",
}

standard_headers_media.json:

{
  "Content-Type": "multipart/form-data"
}

Error:

java.lang.RuntimeException: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String
 (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')

Stactrace:

 Caused by: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String
  (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')
	at org.jsmart.zerocode.core.httpclient.utils.FileUploadUtils.buildOtherRequestParams(FileUploadUtils.java:60)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.createFileUploadRequestBuilder(BasicHttpClient.java:356)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.createRequestBuilder(BasicHttpClient.java:400)
	at org.jsmart.zerocode.core.httpclient.BasicHttpClient.execute(BasicHttpClient.java:126)
	at org.jsmart.zerocode.core.engine.executor.JsonServiceExecutorImpl.executeRESTInternal(JsonServiceExecutorImpl.java:131)
	at org.jsmart.zerocode.core.engine.executor.JsonServiceExecutorImpl.executeRESTService(JsonServiceExecutorImpl.java:92)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rebuggedcommented, Sep 26, 2020

Forked the repo, started working on this. Will raise PR when build is stable.

0reactions
rebuggedcommented, Oct 4, 2020

@authorjapps reminder! the PR has been pending for a while. Please can you help to merge it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot controller - Upload Multipart and JSON to DTO
Your endpoint takes only one param, which is file and of type multipart form data. Mine is a combinatio of json and multipart....
Read more >
java.lang.String cannot be cast to com.vordel.mime.Body
Resolution. The class com.vordel.mime.Body has several different sub-types that reference different types of content, so it will break ...
Read more >
Fix list for IBM WebSphere Application Server V8.5
The following is a complete listing of fixes for V8.5 with the most recent fix at the top. Content. Back to all versions ......
Read more >
Apache Tomcat 8 (8.5.84) - Changelog
#550: Correctly handle case where a Servlet responds to a request with an expectation with a 2xx response without reading the request body....
Read more >
ryanwu/rn-fetch-blob - Gitee
Upload a file from storage; Multipart/form-data example: Post form data with file and ... When the body is an Array we will set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found