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 8611895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:29:22+00:00 2026-06-12T04:29:22+00:00

I’m working with a system that generates this type of XML: <address> <addressLine>123 Main

  • 0

I’m working with a system that generates this type of XML:

<address>
  <addressLine>123 Main Street</addressLine>
  <addressLine>Suite 123</addressLine>
  <city>Test City</city>
  <stateOrProvince>AA</stateOrProvince>
  <postalCode>00000</postalCode>
</address>

The two addressLine elements should be part of an XStream implicit collection – I’d like to call a getAddressLine() method and get a List<String> output.

I’ve been working with XStream’s tutorial and haven’t quite figured out how to get the addressLine elements to map correctly. There’s a similar use case in XStream’s Tweaking Output tutorial, but no example code is provided:

Another use case are collections, arrays and maps. If a class has a
field that is a one of those types, by default all of its elements are
embedded in an element that represents the container object itself. By
configuring the XStream with the XStream.addImplicitCollection(),
XStream.addImplicitArray(), and XStream.addImplicitMap() methods it is
possible to keep the elements directly as child of the class and the
surrounding tag for the container object is omitted. It is even
possible to declare more than one implicit collection, array or map
for a class, but the elements must then be distinguishable to populate
the different containers correctly at deserialization.

In the following example the Java type representing the farm may have
two containers, one for cats and one for dogs:

<farm>
  <cat>Garfield</cat>
  <cat>Arlene</cat>
  <cat>Nermal</cat>
  <dog>Odie</dog>
</farm>

However, this SO answer suggests that the XStream farm example is not possible.

I’ve tried this Java code to unit test my Java code, but no luck yet:

XStream xstream = new XStream(new StaxDriver());        
xstream.alias("address", Address.class);
xstream.alias("addressLine", String.class);     
xstream.addImplicitCollection(Address.class, "addressLines");       

Address address = (Address) xstream.fromXML( 
    new FileInputStream("src/test/resources/addressTest.xml"));

Are there any other configuration changes I should try?

Note: I’m currently using XStream v1.2.2.

  • 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-12T04:29:23+00:00Added an answer on June 12, 2026 at 4:29 am

    First, if possible you should upgrade to a more recent XStream – 1.2.2 was released in 2007. But to answer your question, try:

    XStream xstream = new XStream(new StaxDriver());
    xstream.alias("address", Address.class);
    xstream.addImplicitCollection(Address.class, "addressLines", "addressLine", String.class);
    

    This says treat all elements with the name addressLine as Strings, and gather them into the addressLines collection (i.e. someAddress.getAddressLines()).

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

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.