Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Rémi
Contributor
Contributor

Talend ESB 7.2.1 tRESTRequest Json formatting issues

Hi,

I encounter 2 unsolvable issues on Talend ESB tRESTRequest component (i beg).

I created an ESB job beggining with a tRESTRequest component (POST mode) as a first step, which has to process the web service call posting a Json formatted document.

Unfortunately, all my test attempts end up with the following error raise :

"[WARN ]: org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.BadRequestException: HTTP 400 Bad Request"

"Caused by: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: Un caractère XML non valide ou non admis est indiqué. "

The JSon document to process contains :

  • some field names with "$" characters : for example, "currency$_identifier"
  • some nodes formatted like the following example, with a value ID without field name, preceding the data to process :

   "taxes": {

    "745BDD811EB9438DA4682086CB0B6F52": {

    "id": "745BDD811EB9438DA4682086CB0B6F52",

    "net": 24.17,

    "amount": 4.83,

    "name": "TVA 20% FR",

    "docTaxAmount": "D",

    "rate": 20,

    "taxBase": null,

    "cascade": false,

    "lineNo": 10

    }

   }

Without those fields/special nodes in the Json document, everything works fine and i have no problem.

Thanks by advance for all your comments/advices !

Rémi

Labels (3)
7 Replies
Anonymous
Not applicable

Hi

It is an invalid Json string, ​the json API can not parse it and throws the error, we can do nothing on Json API, is it possible to update the json string to an valid one before passing it web service?

 

Regards

Shong

Rémi
Contributor
Contributor
Author

Hi shong and thx for your precious feedback.

Is there any way of bypassing the auto-convertion in the tRESTRequest ? I mean, could we use another Talend component just before the tRESTRequest uses its json API auto-parsing, to clean this formatting issues ?

And for you, according to your answer, what is really incorrect in this Json ?

  • the $ character not allowed on a Json field name ?
  • the taxes node with a dynamic value "745BDD811EB9438DA4682086CB0B6F52": directly in the field without any field name ? instead of the pattern "key : value" ?

thx a lot !

Rémi

Anonymous
Not applicable

Hi Remi,

How do you pass this Json string to web service? tRestRequest does not have the auto-convertion functionality, the json string should be corrected before web service is calling.

There are some online Json validator, such as https://jsonlint.com/, you can check the json string.

 

Regards

Shong

Rémi
Contributor
Contributor
Author

hi shong and thx for your replies.

 

I don't have any control over the WS Call. It comes from an application, for which i asked some adjustments because of this issue in Talend. Moreover the technical managers of this application maintain they had not encountered such issue about the json format, which is a correct one for them.

 

It's curious because when i post en example of Json on the link you provided me, it tells me it's a valid json ! But it can't go through a Talend ESB tRESTRequest without crashing it with a "404 bad request", as soon as i keep the field name containing "$" properties and the weird taxes node with the "value itself without any key name".

 

That keeps me puzzled 🙂

Anonymous
Not applicable

I tested the example json provided by you in the first post and it shows invalid. How do you pass the Json to tRESTRequest? Through parameters?

 

 

gjeremy1617088143

Hi if you want to make it valid, just encapsulate the wole with {} :

 

{

  "taxes":{

     "745BDD811EB9438DA4682086CB0B6F52":{

        "id":"745BDD811EB9438DA4682086CB0B6F52",

        "net":24.17,

        "amount":4.83,

        "name":"TVA 20% FR",

        "docTaxAmount":"D",

        "rate":20,

        "taxBase":null,

        "cascade":false,

        "lineNo":10

     }

  }

}

 

will work, but here it's just a node you send it's not the full json

gjeremy1617088143

could you send a full created json ? To see what you have to transform to make it valid ?

 

  • -the taxes node with a dynamic value "745BDD811EB9438DA4682086CB0B6F52": directly in the field without any field name ? instead of the pattern "key : value" ?

:

it is ok cause his value is a list of value in the {} just after(but it create a dynamic field name wich is surely not supported on the api parser), you have to see the structure the api want for your json.

 

and $ in field name doesn't seem to cause any problem for a valid json but will can create error on some parser you could use $$ instead it seems to work.