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

  • Home
  • SEARCH
  • 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 6957913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:04:22+00:00 2026-05-27T15:04:22+00:00

I’ve recompiled some of my code under Java 7 and started testing. Quite soon

  • 0

I’ve recompiled some of my code under Java 7 and started testing. Quite soon I’ve noticed that mechanism I used for serialization of objects to xml stopped working. Luckily this serialization is for temporary session storage purpose so I could remove all old serialized XMLs and start from scratch using xstream instead of XMLEncoder.

I’m curious what have I done wrong or what changed in the XMLEncoder shipped with Java7.

B.java:

import java.util.*;
public class B{
        public String s;
        public void setS(String s){
                this.s = s;
        }
        public String getS(){
                return this.s;
        }
        public HashSet<String> h = new HashSet<String>();
        public void setH(HashSet<String> h){
                this.h = h;
        }
        public HashSet<String> getH(){
                return this.h;
        }
}

A.java:

import java.util.*;
import java.io.*;
import java.beans.*;
class A{
        public A(){
                B tmp = new B();
                tmp.setS("abc");
                HashSet<String>h = new HashSet<String>(Arrays.asList("a", "c"));
                tmp.setH(h);

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                XMLEncoder e = new XMLEncoder( new BufferedOutputStream(bos) );
                e.writeObject( tmp );
                e.close();
                System.out.println(bos.toString());
        }
        public static void main(String []arg){
                new A();
        }
}

Running A under java 1.6.x gives me:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0_25" class="java.beans.XMLDecoder">
 <object class="B">
  <void property="h">
   <void method="add">
    <string>b</string>
   </void>
   <void method="add">
    <string>a</string>
   </void>
  </void>
  <void property="s">
   <string>abc</string>
  </void>
 </object>
</java>

Running A under java 1.7.0_01 gives me:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_01" class="java.beans.XMLDecoder">
 <object class="B" id="B0">
  <void class="B" method="getField">
   <string>s</string>
   <void method="set">
    <object idref="B0"/>
    <string>abc</string>
   </void>
  </void>
 </object>
</java>

As you can see the output does not contain any trace of the HashSet h field.

I’ve done some googling but so far the only similar case that I could find is this post, nothing else.

Thanks in advance for your hints.

  • 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-27T15:04:23+00:00Added an answer on May 27, 2026 at 3:04 pm

    You need to make your data members private in Class B and it will work fine. try this code.

    private String s;
    private HashSet<String> h = new HashSet<String>();
    

    You need to follow java conventions in defining all your classes. XMLEncode will use getter/setter methods to properly convert objects into xml.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.