How to deserialize array of objects in incoming webhook payload?

Willem Prins December 29, 2021
Hello!

When trying to update an issue description via an incoming webhook using the project automation tools (/jira/software/c/projects/PROJECT-KEY/settings/automate), the JSON parser errors out when trying to parse a collection (an array of objects), assuming that the array bracket opens a 'regular' list / key-value-pair array.

So when the JSON object in the payload contains something like this:
{
    ...
    "collectionItems": [
        {
            "property": "somevalue"
        },
        {
            "property": "someothervalue"
        }
    ]
}

I get the following error (ignore line / column numbers):


Cannot deserialize instance of `java.lang.String` out of START_OBJECT token at [Source: (ByteArrayInputStream); line: 23, column: 9] (through reference chain: com.codebarrel.automation.api.webhook.IncomingWebhook["collectionItems"]->java.util.ArrayList[0])


Considering that I'm not able to modify the JSON payload, as it comes from another platform service, is there anything I can do to make this automation work?

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2021

Hi @Willem Prins 

Without seeing your complete rule and the response structure, my recommendation is to use the text and list handing functions, conditional list filtering, and to progressively write pieces of the response to the audit log.  That may uncover if this is a problem identifying the structure in the response or an actual defect with parsing. 

Here are some references to help with those steps:

Kind regards,
Bill

Willem Prins January 3, 2022

Hi @Bill Sheboy 

Thanks for those links, it's good to know have these resources for working with smart values.

I created a new webhook to test my filtering options, and it seems the problem is that I cannot do perform any type of smartvalue handling because the payload as a whole is rejected when a parse error occurs. As soon as I replace the collection with a regular nested object, I can work with the payload.

So in my case, any curly bracket "{" that follows a "[" causes a parse error, which would be the case for any webhook where the body contains a collection of objects. Considering that this seems to be a pretty common and valid JSON construct, I'm surprised that this cannot be parsed:

From the spec:

> An array is an ordered collection of values [..] A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2022

Hi, Willem!

One more thing to try: save the response as a created variable to convert it to a string and then try to parse it, using text and list functions.

If that still doesn't work, I recommend working with your site admin to submit a ticket to Atlassian Support here: https://support.atlassian.com/contact/#/  They may see something else to help.  Once you hear back from them please post what you learn to benefit the community.  Thanks!

Willem Prins January 11, 2022

Hi Bill, thanks for staying with us here. Sadly, there's no way to get that response or save it to a variable because the automation errors out when it cannot parse the payload.

Thanks for the tip about contacting support though, I'll reach out to my admin and try and find answers there.

Luckily our amazing third-party service's engineers were able to offer an alternative approach which means we get webhook payloads without an array of objects, so we're not entirely stuck.

Like Bill Sheboy likes this
Tom Daudelin December 1, 2022

Hey @Willem Prins have you been able to figure out a solution to this issue?
I am also running into theses constraints on the REST API side.

Willem Prins December 2, 2022

Hi @Tom Daudelin , we did solve our problem but only were able to do so because the API on the other end was made more flexible so as to send a different kind of payload structure which does not use that kind of array. That's not what you wanted to hear, probably.

Like Syauqi likes this
Tom Daudelin December 2, 2022

Hello! Thank you for the quick response, iI am glad to hear you got it working on your end, but you are right, that was not what I was hoping to hear :(( lol.
Thank you so much though!! 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events