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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:54:23+00:00 2026-06-12T02:54:23+00:00

I am working with xstream to read some xml in the following format —

  • 0

I am working with xstream to read some xml in the following format —

<Objects>
  <Object Type="System.Management.Automation.Internal.Host.InternalHost">
    <Property Name="Name" Type="System.String">ConsoleHost</Property>
    <Property Name="Version" Type="System.Version">2.0</Property>
    <Property Name="InstanceId" Type="System.Guid">7e2156</Property>
  </Object>
</Objects>

Basically under Objects tag there can be n number of Object Type and each Object Type can have n number of Property tags. So I have modelled by Java classes and the code to read it as follows —

class ParentResponseObject {    
    List <ResponseObject>responseObjects = new ArrayList<ResponseObject>();

}

@XStreamAlias("Object")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
class ResponseObject {  
    String Type;   
    String Value; 

    List <Properties> properties = new ArrayList<Properties>(); 
}

@XStreamAlias("Property")
@XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
class Properties {
    String Name;
    String Type;
    String Value;
}
public class MyAgainTest {
    public static void main (String[] args) throws Exception {
        String k1 = //collect the xml as string            
        XStream s = new XStream(new DomDriver());       
        s.alias("Objects", ParentResponseObject.class);
        s.alias("Object",  ResponseObject.class);
        s.alias("Property", Properties.class); 
        s.useAttributeFor(ResponseObject.class, "Type");
        s.addImplicitCollection(ParentResponseObject.class, "responseObjects");     
        s.addImplicitCollection(ResponseObject.class, "properties");
        s.useAttributeFor(Properties.class, "Name");
        s.useAttributeFor(Properties.class, "Type");
    s.processAnnotations(ParentResponseObject.class);       
        ParentResponseObject gh =(ParentResponseObject)s.fromXML(k1);
        System.out.println(gh.toString());
    }
}

Using this code, I am able to populate the responseObjects List in the ParentResponseObject class. However, the properties list in the ResponseObject is always null, even though I am using the same technique in both the cases. Can anyone please help on getting this solved. Help on this is highly appreciated.

  • 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-12T02:54:24+00:00Added an answer on June 12, 2026 at 2:54 am

    Your XML format does not match your Java object model. According to the XML, <Property> is a child of <Objects>, but according to your code, the Properties list is part of the ResponseObject. You need to fix this mismatch.

    Also, it seems that you are using a mix of annotations and code. Either use only annotations (recommended) or do it all in code. Otherwise, your code becomes confusing and unreadable.


    Update:

    I see you have fixed your XML. The problem is that you have a Value field in your ResponseObject, but there is no value in the xml element, so remove it.

    The following code should work:

    @XStreamAlias("Objects")
    public class ParentResponseObject {
    
        @XStreamImplicit
        List<ResponseObject> responseObjects = new ArrayList<ResponseObject>();
    }
    
    @XStreamAlias("Object")
    public class ResponseObject {
    
        @XStreamAsAttribute
        String Type;   
    
        @XStreamImplicit
        List<Properties> properties = new ArrayList<Properties>();
    }
    
    @XStreamAlias("Property")
    @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
    public class Properties {
        String Name;
        String Type;
        String Value;
    }
    

    Main method:

    XStream s = new XStream(new DomDriver());
    s.processAnnotations(ParentResponseObject.class);
    ParentResponseObject gh = (ParentResponseObject) s.fromXML(xml);
    
    for (ResponseObject o : gh.responseObjects) {
         System.out.println(o.Type);
         for (Properties p : o.properties) {
             System.out.println(p.Name + ":" + p.Type + ":" + p.Value);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with xstream to convert some XML into Java objects. The XML
I'm working with a system that generates this type of XML: <address> <addressLine>123 Main
I am using Xstream to serializing a Job object. It looks working fine. but
Working on game where plates will be falling from top to bottom. Some plates
Working with a Lucene index, I have a standard document format that looks something
I am currently deserializing JSON using XStream, and it has been working great. However,
Working with C#. I have an abstract class that I use to read/write settings
Working on a basic form to text file evite list type of thing. Everything
i am working on converting CSV to XML, though i have many ways to
I am working on an app which provides views for some service and acts

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.