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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:10:29+00:00 2026-05-22T16:10:29+00:00

First things first, I’m no asking for a solution but a way to think.

  • 0

First things first, I’m no asking for a solution but a way to think.

I got some data that I need to serialize to check out later… I know how to do it.. but the fields names are the problem…

The data structure contains:

Name of the Field
CoordX
CoordY
Value

(There are like.. 20 different fields. I need to check a biiiggggg string log…)

I could use a single String[][] or several Strings[] … as I said.. the problem is how it appears on the XML…

If I do a single arraylist multidimensional -> [][] I got this

<teste>
      <string-array>
        <string>fieldName</string>
        <string>x</string>
        <string>y</string>
        <string>value</string>
      </string-array>
      <string-array>
        <string>fieldName</string>
        <string>x</string>
        <string>y</string>
        <string>value</string>
      </string-array>
</teste>

And if I do a single string[] I can put the name of the String as the field name

<Fieldname>      
    <string>X</string>
    <string>y</string>
    <string>Value</string>
</Fieldname>

I saw that normal alias is for ALL fields (@XStreamImplicit(itemFieldName=”part”)) and that don’t solve my problem..

It could be worthless if on the other side when I do deserialization, check the log by line and no by field (I know line 1 is field name, line 2 is x..etc)..

So.. what do you guys think?

  • 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-22T16:10:29+00:00Added an answer on May 22, 2026 at 4:10 pm

    I usually design serialization depending on the contents of my “fields”. Say that your name and value fields are relatively small, you could serialize them as

    <list>
      <field name="foo" cordX="12324" cordY="1324" value="value of field foo" />
      <field name="foo" cordX="12324" cordY="1324" value="value of field foo" />
    </list>
    

    of course, if value is long, then you don’t want to serialize it as attribute, but as a regular field value like so:

    <list>
      <field name="foo" cordX="12324" cordY="1324">The long value </field>
      <field name="foo" cordX="12324" cordY="1324">Even longer field value...</field>
    </list>
    

    You can achieve this using XStream like so:

    public class Run {
        public static void main(String[] args) {
            XStream xs = new XStream(new DomDriver());
            xs.processAnnotations(new Class[] { Field.class, Container.class });
            Container c = new Container();
            c.addField("boo", 1,2, "desc");
            c.addField("boo", 1,2, "desc");
            String serialized = xs.toXML(c);
            System.out.println(serialized);
    
            // deserialize
            Container newContainer = (Container) xs.fromXML(serialized);
            if (newContainer.fields.size() != 2) {
                System.out.println("Not deserialized as expected...");
            }
    
            // if you don't want "container"
            xs.alias("mylist", List.class);
            System.out.println(xs.toXML(c.fields));
        }
    }
    

    where you define your Container and Field like so:

    @XStreamAlias("mylistofitems")
    public class Container {
        public List<Field> fields;
    
        public void addField(String name, int x, int y, String desc) {
            if (fields == null) fields = new ArrayList<Field>();
            fields.add(new Field(name, x,y, desc));
    
        }
    }
    
    @XStreamAlias("field")
    public class Field {
        public Field() {}
        public Field(String name, int x, int y, String desc) {
            this.name = name;
            cordX = x;
            cordY = y;
            value = desc;
        }
        @XStreamAsAttribute
        private String name;
        @XStreamAsAttribute
        private int cordX;
        @XStreamAsAttribute
        private int cordY;
        @XStreamAsAttribute
        private String value;
    }
    

    The program gives this output:

    <mylistofitems>
      <fields>
        <field name="boo" cordX="1" cordY="2" value="desc"/>
        <field name="boo" cordX="1" cordY="2" value="desc"/>
      </fields>
    </mylistofitems>
    <mylist>
      <field name="boo" cordX="1" cordY="2" value="desc"/>
      <field name="boo" cordX="1" cordY="2" value="desc"/>
    </mylist>
    

    Hope this helps.

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

Sidebar

Related Questions

One of the first things I learned in C++ was that #include <iostream> int
I know the bits just came out today, but one of the first things
I'm a new guy in PHP OOP concepts. One of the first things that
I have started a new project and on of the first things that I
One of the first things I've learned about Java EE development is that I
First things first, I'd like to make sure the below is the right way
I'm really new to C++ and one of the first things that has me
First things first, I'm using: Java 1.7.0_02 MySQL 5.1.50 ZendServer CE (if that matters)
I recently got asked to review a Visual Studio solution. One of the first
One of the first things I like to do when I make a site

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.