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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:33:20+00:00 2026-06-01T12:33:20+00:00

I have beans which have Objects which can contain different types. Now when I

  • 0

I have beans which have Objects which can contain different types. Now when I create XML it will add class attribute to serialized object. I would like to change that for example class simple name.

Example Java:

public class MyParentClass {

private Object childObjectAttribute; // Can be any instance of any interface ...

// Getters & setters etc..

XStream initialization:

public XStream getXStream()
{
    XStream xstream = new XStream();
    Class<?>[] c = { MyInterfaceImpl.class }; // MyInterfaceImpl has of course @XStreamAlias("MyInterface")
    xstream.processAnnotations(c);
    xstream.alias(MyInterface.class.getSimpleName(), MyInterface.class, MyInterfaceImpl.class);
    return xstream;
}

Example XML:

<myParentClass>
    <childObjectAttribute class="com.example.PossibleClass"/>
</myParentClass>

I would like to change com.example.PossibleClass to PossibleClass or something else. Is that possible?

  • 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-01T12:33:21+00:00Added an answer on June 1, 2026 at 12:33 pm

    Yes you can! It’s helps to reduce the size of generated document. It’s a good practice to do so.
    Use XStream.alias() method.

    This works for me.

    PersonX person = new PersonX("Tito", "George");
    XStream xstream = new XStream();
    xstream.alias("MyPerson", PersonX.class);
    String str = xstream.toXML(person);
    System.out.println(str);
    

    Without alias

    <co.in.test.PersonX>
      <firstName>Tito</firstName>
      <lastName>George</lastName>
    </co.in.test.PersonX>
    

    With alias

    <MyPerson>
      <firstName>Tito</firstName>
      <lastName>George</lastName>
    </MyPerson>
    

    Is the below approach not working?

    workxstream.alias("PossibleClass", PossibleClass.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some beans which I create which all use a similar pattern for
I have two beans which comes from the same class(id1 and id2), the difference
I have a List of beans, each of which has a property which itself
I am using spring to initialise my beans. I have configured a bean which
I'm using JSF 2.0. I have a managed bean which I can access through
I have a wicket page , which contains two Spring-managed beans , one is
I have a bean which extends other Java file. When I create a Spring
I want to create a component which can be used like: <mc:chart data=#{bean.data} width=200
I have two objects: public class ParentObject { // some basic bean info }
I have a strange situation which I hope someone can shed some light on.

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.