Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls to /store/inventory return a 500 code after creating an order with null status #59

Open
ionmariusgabriel opened this issue Feb 24, 2021 · 1 comment

Comments

@ionmariusgabriel
Copy link

Seams that on local after creating an order with null in the status results in the inventory not working anymore and always returning a 500 code with the server logging:
8:56.287 [qtp1407036358-30] ERROR i.s.o.i.utils.DefaultExceptionMapper - There was an error processing your request. It has been logged (ID: 79674d24bfbafb00) com.fasterxml.jackson.databind.JsonMappingException: Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.HashMap["null"])

from the behavior of the online version and the server logs on local that don't seam to notice that the order status is null this issue might be also present on petstore3.swagger.io and not just localhost :)

to reproduce simply get the inventory like so:
curl -X GET "http://localhost:8080/api/v3/store/inventory" -H "accept: application/json"

if it returns a 500 you might have already triggered the issue and need to restart the server and try again BUT
if it works create the following order like so:

curl -X POST "http://localhost:8080/api/v3/store/order" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"id\":10,\"petId\":198772,\"quantity\":7,\"shipDate\":\"2021-02-24T08:34:46.244Z\",\"status\":null,\"complete\":true}"

OR

curl -X POST "http://localhost:8080/api/v3/store/order" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"status\":null}"

and try to get the inventory again.

this consistently returns 500 after that faithful order.

@ionmariusgabriel
Copy link
Author

ionmariusgabriel commented Feb 24, 2021

this can be fixed by not allowing users to create orders and that can be achieved by modifying placeOrder() from OrderController like so:

Before:

public ResponseContext placeOrder(final RequestContext request, final Order order) { if (order == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No Order provided. Try again?"); }

After:

public ResponseContext placeOrder(final RequestContext request, final Order order) { if (order == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("No Order provided. Try again?"); } else if (order.getStatus() == null) { return new ResponseContext() .status(Response.Status.BAD_REQUEST) .entity("Order status cannot be null. Try again?"); }

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

No branches or pull requests

1 participant