How can I set a String array as a variable in the apigee proxy's message context?

Not applicable

I'm using the iloveapis2015-jwr-jwe-jws jwt_signed callout library and it's working well. My only issue is that I'm using a custom claim for user roles that's an array of strings but it's only set in the jwt json as a string field. I see in the code below that the message context could return an array of strings and it should be injected into the json as such. However, setting an array in the message context using KeyValueMapOperations doesn't seem to be possible according to apigee documentation. How can the message context's variable be set as an array of Strings so the code can pick it up? Thank you for your time. Code for reference:

https://github.com/apigee/iloveapis2015-jwt-jwe-jws/blob/master/jwt_signed/callout/src/main/java/com...

My KeyValueMapOperations for reference:

<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="getJwtAttributes" mapIdentifier="jwt">
    <Get assignTo="jwt.claim_role">
        <Key>
            <Parameter>claim_role</Parameter>
        </Key>
    </Get>

Solved Solved
0 1 1,586
1 ACCEPTED SOLUTION

Not applicable

I ended up making a step prior to the java callout which is a javascript callout.

var myVariable = context.getVariable("myVariable");
var myVariableAsArray = myVariable.split(',');
context.setVariable("myVariable", myVariableAsArray);

View solution in original post

1 REPLY 1

Not applicable

I ended up making a step prior to the java callout which is a javascript callout.

var myVariable = context.getVariable("myVariable");
var myVariableAsArray = myVariable.split(',');
context.setVariable("myVariable", myVariableAsArray);