2

I want to submit a form that has file attachment using Ext-JS to a JAX-RS service that is using Jackson to process the JSON.

The problem that i have is that the JSON data doesn't have a Content-Type and I don't know how to set it?

Currently the request body looks something like the following:

-----------------------------4664151417711
Content-Disposition: form-data; name="productBinary"; filename="new.txt"
Content-Type: text/plain

blah
-----------------------------4664151417711
Content-Disposition: form-data; name="myData"

{"MyData": [1,2,3] }
-----------------------------4664151417711--

All good, except that the JSON section doesn't have a Content-Type and therefore I can't get the JAX-RS service to deserialise the JSON into an object

The JAX-RS service is something like:

@POST
@Path("/submit")
@Consumes("mulitipart/form-data")
public String submit( MultipartBody body )
{
    MyData myData = body.getAttachmentObject("myData",MyData.class);
    return "done";
}

any ideas?

UPDATE:

seems that there is no 'nice' way of doing this, instead I found that i need to call the json deserializer directly.

ObjectMapper om = new ObjectMapper();
InputStream is = body.getAttachment("myData").getDataHandler().getInputStream()
MyData md = om.readValue(is,MyData.class);
Krzysztof Safjanowski
  • 7,292
  • 3
  • 35
  • 47
Daniel Walton
  • 218
  • 1
  • 4
  • 17
  • 1
    http://stackoverflow.com/questions/3938569/how-do-i-upload-a-file-with-metadata-using-a-rest-web-service Have a look at this – Ravi Khakhkhar Feb 06 '13 at 13:43

0 Answers0