Discussion:
Flow for transforming Object to JSON?
Adam Causey
2012-01-26 20:34:06 UTC
Permalink
I am trying to take a simple object and have it transformed to JSON format and read over a URL. Here is what I have in my config file, but all it does when I go to the URL is print out a slash (/)... any ideas what I need to do to get the JSON printed?

<json:object-to-json-transformer name="objToJson"
sourceClass="org.mule.TestMe" />

<flow name="jsonTest">
<inbound-endpoint address="http://localhost:9002" exchange-pattern="request-response">
<transformer ref="objToJson" />
</inbound-endpoint>
<echo-component />
</flow>


package org.mule;

public class TestMe {

public String getTest1() {
return "test1";
}

public void setTest1(String test1) {

}

public String getTest2() {
return "test2";
}

public void setTest2(String test2) {

}
}

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Pablo La Greca
2012-01-27 16:48:58 UTC
Permalink
You are using a object-to-json but the inbound endpoint will not get any Object. It will receive some kind of stream that can be JSON.

So you should first convert input to an Object using json-to-object, do something with that object, and finally convert it back to JSON using object-to-json.

HTH, Pablo.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...