Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Entity Creation: Malformed JSON leads to HTTP 500 #42

Closed
mariodavid opened this issue Mar 3, 2021 · 2 comments
Closed

Entity Creation: Malformed JSON leads to HTTP 500 #42

mariodavid opened this issue Mar 3, 2021 · 2 comments
Assignees
Milestone

Comments

@mariodavid
Copy link
Contributor

Given the following malformed JSON structure:

POST {{baseUrl}}
         /entities
         /rstex11_Customer
Authorization: Bearer {{auth_token}}

{
  id: "13f01f59-8e5f-4fd9-802b-66501d49ac99"
  name: "Randall Bishop"
}

(missing the comma between id and name attributes) the result is HTTP 500:

HTTP/1.1 500 

{
  "error": "Server error",
  "details": ""
}

Internal error message:


2021-03-03 10:12:11.489 ERROR 71694 --- [io-8080-exec-10] i.j.r.a.c.RestControllerExceptionHandler : Exception in REST controller

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 3 column 4 path $.id
	at com.google.gson.internal.Streams.parse(Streams.java:60) ~[gson-2.8.6.jar:na]
	at com.google.gson.JsonParser.parseReader(JsonParser.java:85) ~[gson-2.8.6.jar:na]
	at com.google.gson.JsonParser.parseReader(JsonParser.java:60) ~[gson-2.8.6.jar:na]
	at com.google.gson.JsonParser.parseString(JsonParser.java:47) ~[gson-2.8.6.jar:na]
	at com.google.gson.JsonParser.parse(JsonParser.java:98) ~[gson-2.8.6.jar:na]
	at io.jmix.rest.api.service.EntitiesControllerManager.createEntity(EntitiesControllerManager.java:397) ~[jmix-rest-0.3.0.jar:na]
	at io.jmix.rest.api.controller.EntitiesController.createEntity(EntitiesController.java:132) ~[jmix-rest-0.3.0.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_172]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_172]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_172]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_172]
// ...
	... 105 common frames omitted

Expected behavior:

HTTP 400 with an error message explaining that this is not a valid JSON structure.

@mariodavid
Copy link
Contributor Author

see also #35

@mariodavid
Copy link
Contributor Author

Other example:

POST {{baseUrl}}
         /entities
         /rstex11_Order?responseFetchPlan=order-with-details
Authorization: Bearer {{auth_token}}

{
  "customer": {
    "id": "f88597ff-009d-1cf2-4a90-a4fb5b08d835"
  },
  "date": "2021-03-01",
  "amount": 130.08,
  "lines": [
    {
      "product": null
      "quantity": 2
    },
    {
      "product": null
      "quantity": 1
    }
  ]
}

(missing , in each OrderLine instance).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants