Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

JSON parse error only in Apigee (endpoint is fine)

Hi 😊

The POST request has the following json body (which is valid):

[
  "99318858078"
]
 
 
When the request goes through Apigee, I get the following error:
 
Status 400 Bad Request
{
    "message""JSON parse error: Cannot deserialize instance of `br.com.pernambucanas.sacola.dto.CampanhaRequest` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `br.com.pernambucanas.sacola.dto.CampanhaRequest` out of START_ARRAY token\n at [Source: (PushbackInputStream); line: 1, column: 1]"
}

Without Apigee, the request is fine, no problem; so I'm lead to believe the problem is with Apigee trying to get the payload to send to the endpoint?
I printed the request.content in javascript to test it, and it shows like it should (no error, no change in the payload).
 
Does anyone know why this is happening? Is including the "{}" to form an the only way to fix it? And how I can fix it, please?
 
Thank you in advance.
Solved Solved
0 1 2,313
1 ACCEPTED SOLUTION

When the request goes through Apigee, I get the following error: ...

Where do you see this error? I think maybe you're seeing the error in the upstream system.The error message you showed does not look like a message from Apigee.  It seems to be a Java exception, and it refers to the fasterxml library that provides a JSON deserializer. I suspect this error message is coming from your own code (or maybe you don't own that system, but in any case, it's not Apigee code) in the upstream system. It's possible that you see the error first in he Apigee system, but probably the error message originates from the upstream system.  

Obviously, I don't know that upstream code, but I have written Java apps that use the fasterxml library to deserialize and serialize JSON. And I've seen exception messages similar to what you've shown in your post. The fasterxml deserializer is saying it cannot deserialize an object (br.com.pernambucanas.sacola.dto.CampanhaRequest) from an array. And that makes sense. The JSON-serialized form of a typical Java object will start with a curly brace. (always). a JSON that indicates a top-level array (starts with a square brace) will be JSON-deserializable by Jackson as an array. Only. Always. It's possible the DTO class CampanhaRequest is an extension of an Array class. But from the error message, that seems unlikely.

Without Apigee, the request is fine, no problem; so I'm lead to believe the problem is with Apigee trying to get the payload to send to the endpoint?

First, I would ask are you sure that the requests you are comparing are the same?  If the request that goes directly to the upstream system works, and "the same request" routed through Apigee does not work (does not allow the de-serialization in your app code to succeed), then something is changing. But from your description, the change does not appear to be occurring in the payload. Could there be a change in the path, a header, or something else? Can you check those things too? Maybe a change in something other than the payload is causing the upstream system to execute a different code path, when the request is proxied through Apigee. The Apigee trace facility can help you understand the exact request that gets sent to the upstream system.

 

View solution in original post

1 REPLY 1

When the request goes through Apigee, I get the following error: ...

Where do you see this error? I think maybe you're seeing the error in the upstream system.The error message you showed does not look like a message from Apigee.  It seems to be a Java exception, and it refers to the fasterxml library that provides a JSON deserializer. I suspect this error message is coming from your own code (or maybe you don't own that system, but in any case, it's not Apigee code) in the upstream system. It's possible that you see the error first in he Apigee system, but probably the error message originates from the upstream system.  

Obviously, I don't know that upstream code, but I have written Java apps that use the fasterxml library to deserialize and serialize JSON. And I've seen exception messages similar to what you've shown in your post. The fasterxml deserializer is saying it cannot deserialize an object (br.com.pernambucanas.sacola.dto.CampanhaRequest) from an array. And that makes sense. The JSON-serialized form of a typical Java object will start with a curly brace. (always). a JSON that indicates a top-level array (starts with a square brace) will be JSON-deserializable by Jackson as an array. Only. Always. It's possible the DTO class CampanhaRequest is an extension of an Array class. But from the error message, that seems unlikely.

Without Apigee, the request is fine, no problem; so I'm lead to believe the problem is with Apigee trying to get the payload to send to the endpoint?

First, I would ask are you sure that the requests you are comparing are the same?  If the request that goes directly to the upstream system works, and "the same request" routed through Apigee does not work (does not allow the de-serialization in your app code to succeed), then something is changing. But from your description, the change does not appear to be occurring in the payload. Could there be a change in the path, a header, or something else? Can you check those things too? Maybe a change in something other than the payload is causing the upstream system to execute a different code path, when the request is proxied through Apigee. The Apigee trace facility can help you understand the exact request that gets sent to the upstream system.