This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes Marshalling and unmarshallilng java Objects(castoring) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Marshalling and unmarshallilng java Objects(castoring)" Watch "Marshalling and unmarshallilng java Objects(castoring)" New topic

Marshalling and unmarshallilng java Objects(castoring)

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109

Can I castor(Marshal and unMarshal) an HashMap whose key is of type java.lang.reflect.Method and value is of type String . while castoring it throws an exception as

The marshaller cannot marshal/unmarshal types of Void.class, Class.class or Obje

here is the code

import java.util.HashMap;

public class Project
private HashMap aliasMap=new HashMap();

public void setAliasMap(Object method,Object name)

public HashMap getAliasMap()
return aliasMap;


import org.exolab.castor.xml.*;
import java.util.*;
import java.lang.reflect.*;
public class XMLWriter
public static void main(String[] args)
Class loadedClass=null;
Project project=new Project();
catch(Exception e)

Method[] loadingMethods= loadedClass.getMethods();

HashMap aliasMap=new HashMap();

for(int i=0;i<loadingMethods.length;i++)



try {

// write it out as XML
File file = new File("test.xml");
Writer writer = new FileWriter(file);
Marshaller.marshal(project, writer);
// now restore the value and list what we get
Reader reader = new FileReader(file);
Project read = (Project)
Unmarshaller.unmarshal(Project.class, reader);

} catch (Exception ex) {


is there any alternative for storing the hashmap in a permanent location say XML file.while retriveing i need the key of type java.lang.reflect.Method if so suggest me plz.
I agree. Here's the link:
subject: Marshalling and unmarshallilng java Objects(castoring)
It's not a secret anymore!