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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:38:14+00:00 2026-05-17T01:38:14+00:00

I am using XStream to serialize my Objects to XML format. The formatted xml

  • 0

I am using XStream to serialize my Objects to XML format. The formatted xml that I get is as below: node1, node2, node 3 are attributes of pojo,DetailDollars

I have requirement where in I have to calucluate a percentage, for example 100/ 25 and add the new node to the existing ones. So, the final output should be :

<DetailDollars>
    <node1>100 </node1> 
    <node2>25</node2> 
    <node3>10</node3> 
</DetailDollars>

I wrote a custom converter and registered to my xstream object.

public void marshal(..){
         writer.startNode("node4");         
         writer.setValue(getNode1()/ getnode2() );
         writer.endNode();
}

But, the xml stream I get has only the new node:

<DetailDollars> 
    <node4>4</node4>
</DetailDollars>

I am not sure which xstream api would get me the desired format. could you please help me with this .

  • 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-05-17T01:38:14+00:00Added an answer on May 17, 2026 at 1:38 am

    Here is the converter you need:

    public class DetailDollarsConverter extends ReflectionConverter {
    
    public DetailDollarsConverter(Mapper mapper,
            ReflectionProvider reflectionProvider) {
        super(mapper, reflectionProvider);
    }
    
    @Override
    public void marshal(Object obj, HierarchicalStreamWriter writer,
            MarshallingContext context) {
        super.marshal(obj,writer,context);
    
        DetailDollars dl = (DetailDollars) obj;
    
        writer.startNode("node4");
        writer.setValue(Double.toString(dl.getNode1() / dl.getNode2()));
        writer.endNode();
    }
    
    @Override
    public Object unmarshal(HierarchicalStreamReader reader,
            UnmarshallingContext context) {
        return super.unmarshal(reader,context);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public boolean canConvert(Class clazz) {
        return clazz.equals(DetailDollars.class);
    }
    

    }

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

Sidebar

Related Questions

I'm using XStream to serialize some objects to XML, and am facing a problem
I am planning on using XStream with Java to convert between objects and XML
We serialize/deserialize XML using XStream... and just got an OutOfMemory exception. Firstly I don't
I'm using XStream to convert java objects to their XML counterparts. One such object
I am using xstream to de/serialize objects to json. I want to serialize a
I am using XStream to convert XML to objects. I am converting large xml.
I am trying to parse an XML file to objects using XStream but I
I am trying to flatten the xml output of xstream using a converter/marshaling with
I was using XStream for deserialization of xml in my Android app, and now
This is My Xml generated using xstream <Request> <MSISDN>9900624233</MSISDN> <TRANSID>123456</TRANSID> </Request> i want to

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.