Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,754
Community Members
 
Community Events
176
Community Groups

How to deserialize array of objects in incoming webhook payload?

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

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

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.

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!

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

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.

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.

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

Atlassian Community Events