You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sarfaraj <sa...@gmail.com> on 2013/05/03 15:03:20 UTC
Issue in JSON marshalling
I have camel route which exposes web service. I want to accept a data from
web client and convert to JSON object.
Curently i am using SOAP UI to send input to above web service.
# Here is my input.......
<soapenv:Body>
<aaa:myData>
<arg0>
<id>1</id>
<name>abc</name>
</arg0>
</aaa:myData>
</soapenv:Body>
# My camel route is
<dataFormats>
<json id="jack" library="Jackson" />
</dataFormats>
<route id="tcaRoute">
<from uri="cxf:bean:soapEndpoint" />
<marshal ref="jack" />
<to uri="file:src/main/resources/out.txt" />
</route>
After running this, I get following Output i.e JSON data
[{"id":1,"name":"abc"}]
So instead of [{"id":1,"name":"abc"}] , I need
{"*myData*":{"id":1,"name":"abc"}} because id and name are member of myData
class.
Here it only return class member not the class.
Addition to above i also want to remove "[]" from JSON output.
*Could some one tell me what changes i need to do on JSON data format to
achive this?*
/Note: i referred http://camel.apache.org/json.html/
/Sarfaraj
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-in-JSON-marshalling-tp5731970.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue in JSON marshalling
Posted by sarfaraj <sa...@gmail.com>.
You took question wrongly.
I am asking that property in JSON not in xmljson .
We have POJO object which we want to convert to JSON. xmljson is for XML to
JSON not for Object to JSON.
Currently JSON return [{"id":1,"name":"abc"}]
But instead of [{"id":1,"name":"abc"}] , we need
{"*myData*":{"id":1,"name":"abc"}}
/Sarfaraj
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-in-JSON-marshalling-tp5731970p5732008.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue in JSON marshalling
Posted by Chris Wolf <cw...@gmail.com>.
Disregard my remark about using Spring to configure - I should have
read further down
on that page I referenced. You can do this:
<dataFormats>
<xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
trimSpaces="true"
removeNamespacePrefixes="true" expandableProperties="d e"/>
</dataFormats>
On Fri, May 3, 2013 at 2:55 PM, Chris Wolf <cw...@gmail.com> wrote:
> I an answer the first part:
>
> xmlJsonFormat.setForceTopLevelObject(true);
>
> See:
>
> http://camel.apache.org/xmljson.html
>
> You might need to instantiate the XmlJsonDataFormat using Spring bean rather
> then Camel <dataFormats><json/>
>
> Currently I'm using Java-DSL, but I think it would look like:
>
> <bean id="jack" class="org.apache.camel.model.dataformat.XmlJsonDataFormat">
> <property name="setForceTopLevelObject" value="true"/>
> </bean>
>
> or, if you include the 'p' namespace:
>
> xmlns:p="http://www.springframework.org/schema/p"
>
>
> <bean id="jack" class="org.apache.camel.model.dataformat.XmlJsonDataFormat"
> p:setForceTopLevelObject="true"/>
>
>
> On Fri, May 3, 2013 at 9:03 AM, sarfaraj <sa...@gmail.com> wrote:
>>
>> I have camel route which exposes web service. I want to accept a data from
>> web client and convert to JSON object.
>> Curently i am using SOAP UI to send input to above web service.
>>
>> # Here is my input.......
>> <soapenv:Body>
>> <aaa:myData>
>> <arg0>
>> <id>1</id>
>> <name>abc</name>
>> </arg0>
>> </aaa:myData>
>> </soapenv:Body>
>>
>> # My camel route is
>>
>> <dataFormats>
>> <json id="jack" library="Jackson" />
>> </dataFormats>
>>
>> <route id="tcaRoute">
>> <from uri="cxf:bean:soapEndpoint" />
>> <marshal ref="jack" />
>> <to uri="file:src/main/resources/out.txt" />
>> </route>
>>
>> After running this, I get following Output i.e JSON data
>> [{"id":1,"name":"abc"}]
>>
>> So instead of [{"id":1,"name":"abc"}] , I need
>> {"*myData*":{"id":1,"name":"abc"}} because id and name are member of myData
>> class.
>> Here it only return class member not the class.
>> Addition to above i also want to remove "[]" from JSON output.
>>
>> *Could some one tell me what changes i need to do on JSON data format to
>> achive this?*
>>
>> /Note: i referred http://camel.apache.org/json.html/
>>
>> /Sarfaraj
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Issue-in-JSON-marshalling-tp5731970.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue in JSON marshalling
Posted by Chris Wolf <cw...@gmail.com>.
I an answer the first part:
xmlJsonFormat.setForceTopLevelObject(true);
See:
http://camel.apache.org/xmljson.html
You might need to instantiate the XmlJsonDataFormat using Spring bean rather
then Camel <dataFormats><json/>
Currently I'm using Java-DSL, but I think it would look like:
<bean id="jack" class="org.apache.camel.model.dataformat.XmlJsonDataFormat">
<property name="setForceTopLevelObject" value="true"/>
</bean>
or, if you include the 'p' namespace:
xmlns:p="http://www.springframework.org/schema/p"
<bean id="jack" class="org.apache.camel.model.dataformat.XmlJsonDataFormat"
p:setForceTopLevelObject="true"/>
On Fri, May 3, 2013 at 9:03 AM, sarfaraj <sa...@gmail.com> wrote:
>
> I have camel route which exposes web service. I want to accept a data from
> web client and convert to JSON object.
> Curently i am using SOAP UI to send input to above web service.
>
> # Here is my input.......
> <soapenv:Body>
> <aaa:myData>
> <arg0>
> <id>1</id>
> <name>abc</name>
> </arg0>
> </aaa:myData>
> </soapenv:Body>
>
> # My camel route is
>
> <dataFormats>
> <json id="jack" library="Jackson" />
> </dataFormats>
>
> <route id="tcaRoute">
> <from uri="cxf:bean:soapEndpoint" />
> <marshal ref="jack" />
> <to uri="file:src/main/resources/out.txt" />
> </route>
>
> After running this, I get following Output i.e JSON data
> [{"id":1,"name":"abc"}]
>
> So instead of [{"id":1,"name":"abc"}] , I need
> {"*myData*":{"id":1,"name":"abc"}} because id and name are member of myData
> class.
> Here it only return class member not the class.
> Addition to above i also want to remove "[]" from JSON output.
>
> *Could some one tell me what changes i need to do on JSON data format to
> achive this?*
>
> /Note: i referred http://camel.apache.org/json.html/
>
> /Sarfaraj
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Issue-in-JSON-marshalling-tp5731970.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Issue in JSON marshalling
Posted by sarfaraj <sa...@gmail.com>.
*can we have property like we have "forceTopLevelObject" in xmljson ?*
--
View this message in context: http://camel.465427.n5.nabble.com/Issue-in-JSON-marshalling-tp5731970p5731996.html
Sent from the Camel - Users mailing list archive at Nabble.com.