0
votes

I am attempting to generate an object from incoming XML string. This is the incoming payload which shows as a java.string after converting it from byte array to object:

<?xml version="1.0" encoding="utf-8"?>
<EnumerationResults ContainerName="http://xxx.blob.core.windows.net/123/">
<Blobs>
<Blob>
<Name>stuff.csv</Name><Url>http://xxx.blob.core.windows.net/123/location.csv</Url><LastModified>Tue, 25 Aug 2015 18:19:58 GMT</LastModified><Etag>0x8D2AD79C8DFFFFF</Etag>
<Size>177</Size>
<ContentType>application/octet-stream</ContentType>
<ContentEncoding /><ContentLanguage />
</Blob>
</Blobs>
<NextMarker />
</EnumerationResults>"

I created a class that I tried to map the above with:

public class EnumerationResults implements java.io.Serializable{
    static final long serialVersionUID = 1;

    private List<Blob> Blobs;
    private String NextMarker;

    private String ContainerName;

    public EnumerationResults(){} 

    public List<Blob> getBlobs() {
        return Blobs;
    }
    public void setBlobs(List<Blob> Blobs) {
        this.Blobs = Blobs;
    }

    public String getNextMarker(){
        return NextMarker;
    }
    public void setNextMarker(String NextMarker){
        this.NextMarker = NextMarker;
    }
}

using an Xml to Object transformer or a XML to JAXB transformer, but got :

org.mule.api.transformer.TransformerMessagingException: EnumerationResults (com.thoughtworks.xstream.mapper.CannotResolveClassException). Message payload is of type: String

Could someone tell me what the best approach to transforming this would be? I have also tried object to JSON and then tried mapping JSON to the java class but the mapper through errors.

Thanks for any input.

3
UPDATE: It appears that the real problem is that when the data comes in via the RestApi call from Azure and is transformed from BufferInputStream to to Xml via the Dom to Xml transformer it is of type "java.lang.string". I have tried all kinds of alternate, initial transformers and they all result in a "java.lang.string" From that point transformation to an object is prevented ....it appears.KickinMhl

3 Answers

2
votes

Finally found a solution to this issue using these flow steps:

  • use dom to xml transformer
  • xml to json transformer
  • JSON to Object with return class of 'java.util.Map'

I doubt this is the best solution, but it'll do for now.

1
votes

if you are using mule 3.7 use data weave to transform or else go for a datamapper

0
votes

If datamapper and dataweave is not your option (perhaps your on Community edition), the try map your XML to a JAXB Object.

Mule has XML to JAXB Object transformer you can use. You only need to create the JAXB Object class.

Example class with JAXB annotations

@XmlRootElement(name = "person")
@XmlAccessorType(XmlAccessType.FIELD)
public class Person
{
    private String name;
    private String dob;

    @XmlElementWrapper(name = "emailAddresses")
    @XmlElement(name = "emailAddress")
    private List<EmailAddress> emailAddresses;

    public String getName() { return name; }

    public void setName(String name) { this.name = name; }

    public String getDob() { return dob; }

    public void setDob(String dob) { this.dob = dob; }

    public List<EmailAddress> getEmailAddresses() { return emailAddresses; }

    public void setEmailAddresses(List<EmailAddress> emailAddresses) { this.emailAddresses = emailAddresses; }
}

You can create JAXB class from XSD via xjc command.