Convert or Cast HashMap to Properties Object

I have a Properties object that because of transfer over a SOAP web service becomes a generic object on the other side.  My goal is to get that object to become a Properties object again. I can get it into a HashMap but can't get any further.

Any ideas?
LVL 1
fatttymeltAsked:
Who is Participating?
 
objectsCommented:
Assuming it is a Properties object you can use:

Properties props = (Properties) object;

If its a Map use:

Properties props = new Properties();
props.putAll(map);
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> I can get it into a HashMap but can't get any further.

How are you doing that?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can of course, loop through the collection and add its values to another kind of collection
0
 
fatttymeltAuthor Commented:
I can get it into a HashMap by doing

HashMap hashmap = (HashMap) object;

But trying

Properties props = (Properties) object;

results in a "ClassCastException: java.util.HashMap" error.
"Objects" suggestion worked

Map map = (Map) myObject.getMetaData(); // getMetaData returns a generic object that was once a HashMap
Properties props = new Properties();
props.putAll(map);

And that works for me. Thanks.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> results in a "ClassCastException: java.util.HashMap" error.

That's because the object is not a Properties instance. You need to create a Properties instance out of it (by creating a new one and adding the data)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.