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
09:57:20,351 INFO Using default type string
Exception in component tRESTClient_3
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.apache.cxf.jaxrs.client.AbstractClient.convertToWebApplicationException(
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(
at org.apache.cxf.jaxrs.client.WebClient.invoke(
at vu_mdm_title.writeback_0_1.Writeback.tWriteJSONField_1_InProcess(
at vu_mdm_title.writeback_0_1.Writeback$
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

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.
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
<ID> 1234 </ID>
<Name> "Name" </Name>
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:

Re: Data types in document from tWriteJSONField

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 ?
Four Stars

Re: Data types in document from tWriteJSONField

Suggestion by shong to create a json file


Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs