I'm looking for a simple solution.
I have a xml file:
<properties>
<property>
<class>java.lang.String</class>
<value>String value...</value>
</property>
<property>
<class>java.lang.Boolean</class>
<value>true</value>
</property>
<!-- ... others java lang wrapper class -->
</properties>
I would like to do a dynamic parser.
I know that I can read the xml with org.w3c.dom.* and org.w3c.dom.Node.getTextContent() I can get the value of the tag.
Class<?> clazz = Class.forName(classTextContent);
// How to convert value to specific clazz?
// if/else (clazz)? Does not look a nice answer.
Any suggestion?
[Edited] By reflection:
The variable "clazz " is a java.lang.Class, right? How can I convert textContent value (in String) to any wrapper type?
Object objectValue = null;
Class<?> clazz = Class.forName(nodeClass.getTextContent());
String value = nodeValue.getTextContent();
if (clazz.equals(Boolean.class) { objectValue = Boolean.valueOf(value) }
valueOf could be a generic method that I could call using reflection... Integer, Float, Boolean, Long, Double support valueOf.
Another way?