XML name to Scala type mapping for binding fromXML #177

jkida opened this Issue Dec 3, 2012 · 0 comments


None yet
1 participant

jkida commented Dec 3, 2012

originally posted as Best way to automatically determine class for binding fromXML.

I am developing an application for a system that will need to process an inbound XML stream. I currently have scalaxb working where I can create an object by using scalaxb.fromXML[SomeClass](xmlElement).

My question is what is the best way I can match the XML element to the class it belongs with. I am thinking a case statement, but what is the cleanest way to do this?

For example.. lets say the following XML element comes in... which could be 1 of a couple dozen different elements/classes

val xmlStream = <Person>

xmlStream match {
Not_Sure_What_To_Match => scalaxb.fromXML[Person](xmlStream)
... other XML elements...

Can someone give me some suggestions on how I can match the XML element to the correct class please.

Does anyone have any suggestions on how I can take my xmlStream and match it to a class? I know in JAXB there was a method getDelclaredType that you could use to return the Class the XML belonged to.


JAXBElement<Object> responseObject = (JAXBElement<Object>) xmlConverter.convertFromXMLToObject(xmlAsString);
Class clazz = responseObject.getDeclaredType();
            if (clazz.equals(BaseEvent.class)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment