Data types in document from tWriteJSONField

One Star

Data types in document from tWriteJSONField

I'm trying to send a POST request to a REST service of JSON format. I am using the tRestClient component which requires an input schema of
body (type: document)
string (type: string)
The service requires a request schema:
{
"ID": Integer,
"Name": "String"
}

When I send the JSON to the tRestClient component, I am getting a Bad Request Exception, I believe it's because the output of tWriteJSON field is outputting column1 as a string rather than an integer (i.e. it is enclosed in double quotes). You can see this in the code below.
How do I manipulate the data types of the values from the tWriteJSONfield component, while still keeping the output schema of type document (as is required for the tRestClient component).

 connecting to socket on port 3534
connected
09:57:20,351 INFO Using default type string
|{"ID":"34842","Name":"Name1"}
Exception in component tRESTClient_3
javax.ws.rs.BadRequestException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(AbstractClient.java:452)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:858)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:829)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:392)
at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:418)
at vu_mdm_title.writeback_0_1.Writeback.tWriteJSONField_1_InProcess(Writeback.java:5833)
at vu_mdm_title.writeback_0_1.Writeback$1ThreadXMLField_tWriteJSONField_1_Out.run(Writeback.java:3329)
disconnected
Job Writeback ended at 09:57 27/03/2014.

If I set the output of tWriteJSON to be of type int and string (instead of document and string) then the tRestClient component throws a "body/string cannot be resolved" error.
Community Manager

Re: Data types in document from tWriteJSONField

Hi
To pass a request with json format to a rest web service, use a tXMLMap, instead of tWriteJsonField, to build a document before tRestClient, and select json option from the accept type list on tRestClient.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Data types in document from tWriteJSONField

Hi Shong,
How do I build a JSON with the tXMLMap component?
My understanding is that it would output an XML document like
<root>
<ID> 1234 </ID>
<Name> "Name" </Name>
</root>
which isn't what I need. My initial input is 2 columns, which I need to format into a JSON before it goes through to the tRestClient component.
One Star

Re: Data types in document from tWriteJSONField

bump. Shong could you please expand on your answer?
One Star

Re: Data types in document from tWriteJSONField

What is the work around to this issue?
Still seems to be a major problem:
https://jira.talendforge.org/browse/TDI-25966?page=com.atlassian.jira.plugin.system.issuetabpanels%3...
Employee

Re: Data types in document from tWriteJSONField

Hi.
These are the options I'm aware of:
- Use tXMLMap with tRESTClient - this relies on the internal CXF DOM4J (XML) to JSON auto conversion. If you go this way then you can also have the root dropped, etc, there are few JSON related properties in tRESTClient/Advanced
- Use other Studio components to create JSON in the String format - and feed it directly into tRESTClient, bypassing tXMLMap
Does it help a bit ?
Sergey
Four Stars

Re: Data types in document from tWriteJSONField

Hi,
Suggestion by shong to create a json file
http://www.talendforge.org/forum/viewtopic.php?pid=132391
Vaibhav