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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:10:21+00:00 2026-05-19T17:10:21+00:00

I have a java class that looks like public class MyClass { private final

  • 0

I have a java class that looks like

public class MyClass {
   private final String str;
   private Polygon polygon; // this polygon is a custom type of mine
}

I have an xml file that has an instance of MyClass written to it using XStream.

Now MyClass has changed and polygon has been replaced with List<Polygon> and the field has been renamed to polygons, and I’m trying not to break deserialization. I want to change the deserialization of the polygon field to basically read the polygon and then just create a new list and add the single polygon to it. The list would then be the new field value.

Is it possible to change the conversion of just this one field? Or do I need to write a custom converter for the whole class MyClass?

thanks,
Jeff

  • 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-19T17:10:21+00:00Added an answer on May 19, 2026 at 5:10 pm

    So based on your comment, I believe you’ll need a custom converter.

    Here’s an example:

    import com.thoughtworks.xstream.converters.Converter;
    import com.thoughtworks.xstream.converters.MarshallingContext;
    import com.thoughtworks.xstream.converters.UnmarshallingContext;
    import com.thoughtworks.xstream.io.HierarchicalStreamReader;
    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
    
    public class MyClassConverter implements Converter{
    
        @Override
        public boolean canConvert(Class clazz) 
        {
            return clazz.equals(MyClass.class);
        }
    
        @Override
        public void marshal(Object value, HierarchicalStreamWriter writer,
                MarshallingContext context) 
        {
    
        }
    
        @Override
        public Object unmarshal(HierarchicalStreamReader reader,
                UnmarshallingContext context) 
        {
            // Create MyClass Object
            MyClass myClass = new MyClass();
    
            // Traverse Tree
            while (reader.hasMoreChildren()) 
            {
                reader.moveDown();
                if ("polygon".equals(reader.getNodeName())) 
                {
                    Polygon polygon = (Polygon)context.convertAnother(myClass, Polygon.class);
                    myClass.addPolygon(polygon);
                } 
                reader.moveUp();
            }
    
            // Return MyClass Object
            return myClass;
        }
    }
    

    In case you’re unawares, here’s a reference guide: http://x-stream.github.io/converter-tutorial.html

    Now, all that’s left to do is register your converter, which I’m assuming you know how to do. Anyway, an important, although obvious thing to note is that ‘addPolygon’ is a method I used to populate your new list object.

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

Sidebar

Related Questions

Suppose that I have a Java class with a static method, like so: class
I have a java class that applies an xslt to all xml files in
I need your expertise once again. I have a java class that searches a
I have a really simple Java class that effectively decorates a Map with input
In Java, say you have a class that wraps an ArrayList (or any collection)
I have a Java program that loads thirdparty class files (classes I did not
I have a java class which fires custom java events. The structure of the
I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If
If I have a Java source file (*.java) or a class file (*.class), how

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.