Question

I am trying to utilize the xml to object transformer in mule while transfroming an xml payload to a Java Bean (Customer). Here is my simple flow. The exception I am seeing is below

Exception stack is:
1. CUSTOMER (com.thoughtworks.xstream.mapper.CannotResolveClassException)
  com.thoughtworks.xstream.mapper.DefaultMapper:56 (null)
2. CUSTOMER (com.thoughtworks.xstream.mapper.CannotResolveClassException) (org.mule.api.transformer.TransformerException)
  org.mule.module.xml.transformer.XmlToObject:76 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.mapper.CannotResolveClassException: CUSTOMER
    at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)
    at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)
    at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

FLOW

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <flow name="alternateFlow1" doc:name="alternateFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8999" doc:name="HTTP"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="www.thomas-bayer.com" port="80" path="sqlrest/CUSTOMER/3/" method="GET" doc:name="HTTP"/>
        <mulexml:xml-to-object-transformer returnClass="com.abc.dto.CUSTOMER" doc:name="XML to Object"/>
        <logger level="INFO" doc:name="Logger"/>
    </flow>
</mule>

XML:

<CUSTOMER xmlns:xlink="w3.org/1999/xlink">
 ;
 <ID>4</ID>
 <FIRSTNAME>Sylvia</FIRSTNAME>
 <LASTNAME>Ringer</LASTNAME>
 <STREET>365 College Av.</STREET>
 <CITY>Dallas</CITY>
</CUSTOMER>
Was it helpful?

Solution

You need to add an alias in the mulexml:xml-to-object-transformer:

<mulexml:alias name="CUSTOMER" class="com.abc.dto.CUSTOMER" />

Also there's no reason to go all caps with the class name so rename your class and alias it:

<mulexml:alias name="CUSTOMER" class="com.abc.dto.Customer" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top