Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:42:06+00:00 2026-06-03T13:42:06+00:00

I have a problem with sending ArrayList from server to my client using JAX-rs.

  • 0

I have a problem with sending ArrayList from server to my client using JAX-rs. I’ve got 4 classes:

Demo – there is starting REST server
FileDetails – there are 3 fields storing data
ConfigFiles – it has few methods for files and there is a list of FileDetails objects
RestServer – there is method GET

I’ve got the following code:

@XmlRootElement(name="FileDetails")
@Path("/easy")
public class RestSerwer {

    @GET
    @Path("/temporary")
    @Produces("text/temporary")
    public String methodGet() { 
        ConfigFiles cf = ConfigFiles.getInstance();
           List<FileDetails> files = cf.getList();
                   try {
                       JAXBContext ctx = JAXBContext.newInstance(ArrayList.class, FileDetails.class);
                       Marshaller m = ctx.createMarshaller();
                       StringWriter sw = new StringWriter();
                       m.marshal(files, sw);
                       return sw.toString();
                   } catch (JAXBException e) {
                       e.printStackTrace();
                   }
                   return null;
    }
}

At client side I’ve got GetRest:

public class GetRest{

    HttpClient client = null;
    GetMethod method = null;
    private String url = null;

    public GetRest(String url) {
        this.url = url;
    }

    public String getBody(String urlDetail){
           client = new HttpClient();
           method = new GetMethod(url + urlDetail);
           method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
           new DefaultHttpMethodRetryHandler(3, false));
           try {
                client.executeMethod(method);
            } catch (HttpException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }


            byte[] responseBody = null;
            try {
                responseBody = method.getResponseBody();
            } catch (IOException e) {
                e.printStackTrace();
            }finally{                   
                method.releaseConnection();
            }
            String str = new String(responseBody);
            return str;
    }   

    public String getFiles(){   
        return getBody("/easy/temporary");
    }   
}

When I try:

GetRest getRestClass = new GetRest("http://localhost:8185");
                        //List<FileDetails> cf = new ArrayList<FileDetails>();
                        String xxxx = getRestClass.getFiles(); // TODO

It throws:

Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "java.util.ArrayList" as an element because it is missing an @XmlRootElement annotation

At server side.

Anybody can help me?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:42:07+00:00Added an answer on June 3, 2026 at 1:42 pm

    You basically have 2 possibilities: Create you own class which is a wrapper on top of the List or write your own provider and inject it in jersey so that it knows how to marshall/unmarshall the arraylist. Here is a simple code for the first solution:

    @XmlRootElement
    public class MyListWrapper {
    
        @XmlElement(name = "List")
        private List<String> list;
    
        public MyListWrapper() {/*JAXB requires it */
    
        }
    
        public MyListWrapper(List<String> stringList) {
            list = stringList;
        }
    
        public List<String> getStringList() {
            return list;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem, I'm making project and I'm sending data from client
greetings all i have a problem that when sending an email from the server
I have a problem with sending an array using socket.io. The client creates an
Hi I have a problem in sending data from php to pdf. I think
I have a problem when I want to sending data using byte format in
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem while sending messages from android to PC. Messages are send when
I have a problem sending plain text emails using PHPMailer. I have text that
I have a Problem with Parcelable Data in an ArrayList sending via two Activities
i have problem with sending Broadcast receive from one activity to other ..its not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.