in Education by
I am using jersey, and I want to send (in a POST) a list of objects to the server. This is the scenario: @XmlRootElement class Myclass{ //some primitive attributes + empty constructor + getter/setters } MyClass is both on server and client side. @XmlRootElement class MyClasses{ private List classes = new ArrayList(); // put some MyClass into the list } class Sender{ MyClasses list = new MyClasses(); // after client initialization i want to send this list in a POST to server WebResource service = client.resource(baseURI()); //I tried service.type("application/xml").accept("application/xml").post(ClientResponse.class,list); } //on server side @path("/tosend") class receiver{ public Response posted(JAXBElement vals){ //work with vals.getValue() as the list of all Objects } } Unfortunately, I have this error : ContainerRequest getEntity : A Message body reader for JAXBElement and JAXBElement and MIME Type application/octet-stream was not found. How can I fix that? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Are you sure your code looks exactly as written above? The exception suggests you are not setting the content type of the request. Don't use JAXBElement, and make sure the content type of the request is set to application/xml. In your code snippet you seem to be doing it. But the exception says the media type is application/octet-stream. So either the code snippet does not match your real code or the exception is coming from a different section of the code or you have some filters that change the message headers before it reaches the posted() method. Annotate the method with @Consumes(MediaType.APPLICATION_XML). Btw, you don't need to use the MyClasses wrapper class. You can simply send List and it will work as well.

Related questions

0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    What is Client server architecture? List its 2 advantages or disadvantages. Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    I am learning about OAuth2 and OpenID Connect by experimenting with ASP.NET Core and IdentityServer4. So far ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 21, 2022 in Education by JackTerrance
0 votes
    I'm working with ASP.NET 3.5. I have a list box that users must add items to (I've written ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I am currently trying to access Jira REST with Jersey. The problem is that for our Jira a single ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    How how client server model is different from a distributed system? Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the ... of the management studio.) Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    We can pass data from the parent component to the child component by using - 1. Input 2. @Input() 3. Output 4. @Output()...
asked Jun 29, 2021 in Technology by JackTerrance
0 votes
    I am trying to create a pluggable database and am executing commands through sqldeveloper. For enabling the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I have a user interface in .net which needs to receive data from a server, on a request/reply/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Write a program which sends the name of a text file from the client to server and display the message on the ... file present or not. Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    Which of these class is used for operating on request from the client to the server? (a) http (b) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    A list is represented as a vector but can contain objects of ___________ (a) Same class (b) Different class ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    If a client sends an XML request to a server, can we ensure that the communication remains confidential?...
asked Nov 7, 2020 in Education by Editorial Staff
...