wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to Serialize Maps? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Serialize Maps?" Watch "How to Serialize Maps?" New topic
Author

How to Serialize Maps?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
Can someone help me modify my program below so it will serialize a map to standard output? Sun had documented a bug several years ago concerning the serialization of maps and I am hoping it has been fixed by now.
Thanks,
Siegfried

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I ran that code (with the XML from the comments before it) and it produced this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><demoMaps><datum name="xyz_modified"><value>Insert your sample data here_modified</value></datum><datum name="abc"><value>def</value></datum><map/></demoMaps>


Looks okay to me, except for that empty <map> element at the end. Was that what you were referring to? Is it a problem?

Edit: looking at your code it looks like you were expecting the contents of the map to be serialized as well. At least that's what I would expect. So if that's the bug (you didn't say what this bug was) then it's still there.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It'd be easier if you just said what issue you're having. The code works as-is for me once the command is fixed:That ">" at the beginning of line 2 shouldn't be there.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, the map.

Don't you need @XmlJavaTypeAdapter to do maps?

http://www.caucho.com/resin/doc/jaxb-annotations.xtp#@XmlJavaTypeAdapter
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
Sorry -- yup. The map is empty. That is the problem I was hoping was fixed by now. Wow! sun sure is slow at fixing these things.
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
I'm trying to implement the suggested code at http://www.caucho.com/resin/doc/jaxb-annotations.xtp#@XmlJavaTypeAdapter and I need some help.

Can someone help me implement the marshal and unmarshal methods? I'm having trouble understand how class Temp works. Why would marshal return a single temp? Wouldn't it return a java.util.list<Temp>?

Perhaps the problem is that eclipse generated the stub for marshal and unmarshal incorrectly?

Thanks,
Siegfried




Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
I figured it out.

I have a new question now! See my new post.

Thanks,
Siegfried
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Serialize Maps?
 
Similar Threads
How to implement and serialize nested Maps?
Sample on how to work with XPATH
How to have multiple public classes in one file for spring?
How to detect EOF when using java.io.BufferedReader?
Wanted: Help serializing Generic Maps!