Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
Here is a simple class (as a routine file) :
Here is a simple REST API job :
When I use the API, I get this :
Student is displayed a its toString method.
I would like to know if it's possible to get a JSON representation of student ?
I've thought about a solution : use Google GSON library to convert an object into a JSON string, and return this string instead of the object (student like here).
Can you confirm it's a confortable solution ?
Thank you everyone 🙂
You're essentially posting a String into an XML element. You cannot mix like this. What is the full JSON structure you require?
What you need to do here is to build the complete JSON structure and change the Return Body Type of the tRestResponse to String. Then, remove the tXMLMap and simply pass the JSON String (completed) to the body output (which will now be set to String).
It should be pointed out that your JSON array has some errors. I believe it should be structured like this....
{"root":{"student":{"Person":[{"lastname":"A", "firstname":"B", "age":20, "listeRoles":[ "Etudiant", "Test"]}]}}}
You'll need to adjust your routine to enable quotes. The above (hardcoded) in Java would be created like this....
String myValue = "{ \"root\":{ \"student\":{ \"Person\":[ { \"lastname\":\"A\", \"firstname\":\"B\", \"age\":20, \"listeRoles\":[ \"Etudiant\", \"Test\" ] } ] } }}";