JSON requestbody

I’m trying to pass a typescript object over to the portal using JSON.stringify within an angular2 application. However when i debug the code the object is blank. What is the recommended way to pass JSON back and forth?

I also tried to use the api/commit service but continue to get a HTTP Status 500 - java.lang.RuntimeException: Converter not found

Any help would be appreciated.

Thanks!

Hi!
As for the “Converter not found” error, it appears when invalid ‘Content-Type’ header is set in the http request. It should be set to ‘application/json’ in your case. It is described here: https://doc.cuba-platform.com/manual-6.2/rest_api.commit.html.

About the first case, what object are you passing as a JSON? Is it a platform entity or just some POJO? Do you pass it to your custom MVC controller? What do you want to do with it in the controller code?

The JSON information is coming from a typescript model. I’ve basically created a model on the angular side of things that the customer fills in. I then want to send that over to cuba.

When I tried using the Spring MVC route, I was able to call and debug, but it didn’t seem to assign the values from the JSON to the platform entity. I basically got a new instance of the entity.

Here is my method signature with annotations:
@RequestMapping(value = ApplicationEndPoints.CREATE_APP, method = RequestMethod.POST, produces = “application/json”)
String addApplicant(@RequestBody Applicant applicant) throws Exception {

The typescript model matches the platform entity. I’ve named all of the fields the same etc. My assumption was that Spring would read in the json and auto assign each value that it could find a match for…

I also tried to call the platform api/commit and that’s when I get the Converter not found exception:
{host:port}/app-portal/api/commit?s=

Thanks!

Both options should work. Please ensure that your http requests have a ‘Content-Type’ header set to 'application/json’
BTW, there is an example of angular portal. It can be downloaded from the CUBA Studio. On the studio welcome screen go to the Samples tab and find the ‘Portal’ sample there.