blindguyrocketmailcom
New Member
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:\[code\]public void sendEmail(List<String> toRecipients, List<String> ccRecipients, List<String> bccRecipients, String subject, String body) { // code.. }\[/code\]The test email I'm trying to send should come from this XML file:\[code\]<?xml version="1.0" encoding="utf-8"?><email> <to> <recipient>[email protected]</recipient> <recipient>[email protected]</recipient> </to> <cc> <recipient>[email protected]</recipient> </cc> <bcc> <recipient>[email protected]</recipient> </bcc> <subject>test ABC </subject> <body><h1>test XYZ</h1></body></email>\[/code\]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:\[code\]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 } }\[/code\]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:\[code\]Exception in thread "main" com.thoughtworks.xstream.InitializationException: No field "to"\[/code\] for implicit collection