0

I am interested to know if the following scenario is feasible at all: In one request, consume a JSON/XML with a List of custom objects containing some string attributes and a list of files. Something like

public class MyCustomObject{
    String attr1;
    String attr2;
    List<File> files; //FileItem maybe?
//setters getters
}

Rest:

@Path("/test")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@POST
public Response test(List<MyCustomObject> myObjects){
//Do something with objects
}

Thank you for your time :)

Panos Karampis
  • 557
  • 6
  • 18
  • Are you using Jersey? – cassiomolin May 06 '16 at 14:26
  • Yes, Jersey is one library i can use – Panos Karampis May 07 '16 at 00:06
  • I dont see how this is duplicate @peeskillet. The OP on the question wants to post one file with json. I want to achieve similar functionality but consume list. – Panos Karampis May 07 '16 at 00:20
  • You're not going to be able to do this exactly the way you want without custom deserialization. – Paul Samsotha May 07 '16 at 00:26
  • Now that comment makes more sense. It is not duplicate. Ok, seems custom deserialization is the way to go. – Panos Karampis May 07 '16 at 00:29
  • You might want to just get the FormDataMultiPart, and traverse the data yourself. That would be easier than custom deserizialization. – Paul Samsotha May 07 '16 at 00:32
  • I kind of looking to learn, I could also do multiple posts such as you have answered in the other question, but I am gonna go the tough way. If you have some suggestions on some docs i'd be grateful – Panos Karampis May 07 '16 at 00:35
  • You can have a look at [this](https://jersey.java.net/documentation/latest/media.html#d0e9409), [this](https://jersey.java.net/apidocs/2.22.1/jersey/index.html?org/glassfish/jersey/media/multipart/FormDataMultiPart.html) and [this](http://stackoverflow.com/a/34646196/2587435) – Paul Samsotha May 07 '16 at 00:55

0 Answers0