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

  • Home
  • SEARCH
  • 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 9160169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:40:24+00:00 2026-06-17T13:40:24+00:00

I have an application that will spit out a XML file with the contents

  • 0

I have an application that will spit out a XML file with the contents of a email. This XML file will be parsed by a different application and will deliver the email. The part where the application sends the email is validated.

The method that actually sends the email is this:

public void sendEmail(List<String> toRecipients, List<String> ccRecipients, List<String> bccRecipients, String subject, String body) { 

// code.. 

}

The test email I’m trying to send should come from this XML file:

<?xml version="1.0" encoding="utf-8"?>
<email>
  <to>
    <recipient>user1@somecompany.com</recipient>
    <recipient>user2@somecompany.com</recipient>
  </to>
  <cc>
    <recipient>user3@somecompany.com</recipient>
  </cc>
  <bcc>
    <recipient>user5@somecompany.com</recipient>
  </bcc>
  <subject>test ABC </subject>
  <body><h1>test XYZ</h1></body>
</email>

I’m using the XStream library, and my problem resides on parsing a list of . I’ve tried a few different approaches, but am stuck. The XML parsing method is:

private void parseXmlFile(String xmlFilePath) {
        XStream xstream = new XStream(new DomDriver());

        xstream.alias("email", EmailPojo.class);
        xstream.alias("recipient", Recipient.class);
        xstream.alias("to", To.class);
        xstream.alias("cc", Cc.class);
        xstream.alias("bcc", Bcc.class);

        xstream.addImplicitCollection(To.class, "to", "to", Recipient.class);
        // xstream.addImplicitCollection(To.class, "to");
        // xstream.addImplicitCollection(Cc.class, "cc");
        // xstream.addImplicitCollection(Bcc.class, "bcc");

        EmailPojo emailPojo = new EmailPojo();

        StringBuilder sb = new StringBuilder();
        try {
            // filename is filepath string
            BufferedReader br = new BufferedReader(new FileReader(new File(xmlFilePath)));
            String line;

            while ((line = br.readLine()) != null) {
                sb.append(line.trim());
            }
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        List<EmailPojo> emailPojoList = new ArrayList<EmailPojo>();

        try {
            emailPojoList = (List<EmailPojo>) xstream.fromXML(sb.toString());

        } catch (Exception e) {
            emailPojo = null;// TODO: handle exception
        }
    }

THis seems straight forward enough, but I’m not able to get this going.
Wha am I missing here? What’s wrong here?

Thanks in advance!

Edit: forgot the exception output:

Exception in thread "main" com.thoughtworks.xstream.InitializationException: No field "to" for implicit collection

  • 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-17T13:40:26+00:00Added an answer on June 17, 2026 at 1:40 pm

    The line:

    xstream.addImplicitCollection(To.class, "to", "to", Recipient.class);
    

    Is saying there’s a collection field on the class To called to that is where the instances of Recipient should be added.

    Without seeing the To class this is a guess, but I reckon the field on collection field on the class To is more likely to be called recipients which should be registered with:

    xstream.addImplicitCollection(To.class, "recipients", Recipient.class);
    

    See the JavaDoc for xstream.addImplicitCollection(Class, String, Class)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this application that will recurse all folders in a given directory and
We have an application that will capture different images from users and make them
I have an application that will check if a javascript file exists on our
I have a application that will allow a user to upload a file. After
I have an application that will work with the HOSTS file in the Windows\System32\drivers\etc
I have this application that requires me to have a QList which will contain
I have an application that will accept URLs from the built in web browser
I have an application that will return JSON-P data, and I have been communicating
I have an application that will mail users attachments of text files. Receiving users
I have an application that requires resizing of a component that will be scaled

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.