[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1337
  • Last Modified:

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?
0
fatttymelt
Asked:
fatttymelt
  • 3
1 Solution
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now