Input values for customfield_22133

Hi, I am trying to create a request to jira, from my service written in Java. When I create the request and send it from postman, it goes thru, but the customfield_22133 (Impact on) has the following structure.

        "customfield_22133": [
            {"value0": "Customer"},
            {"value1": "Partner"},
            {"value2": "Internal"}
        ]

the description from jira for that field is as follows:

{
"id": "customfield_22133",
"name": "Impact On",
"custom": true,
"orderable": true,
"navigable": true,
"searchable": true,
"clauseNames": [
"cf[22133]",
"Impact On"
],
"schema": {
"type": "array",
"items": "option",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes",
"customId": 22133
}
},

When I am trying to achieve the required result, I chose the approach of creating a ArrayList<HashMap<String, Object>> however, I received the following error:

Caused by: org.codehaus.jettison.json.JSONException: Cannot generate value - unknown type for me: class java.util.HashMap
at com.atlassian.jira.rest.client.internal.json.gen.ComplexIssueInputFieldValueJsonGenerator.generateFieldValueForJson(ComplexIssueInputFieldValueJsonGenerator.java:58) ~[jira-rest-java-client-core-5.2.2.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.gen.ComplexIssueInputFieldValueJsonGenerator.generateFieldValueForJson(ComplexIssueInputFieldValueJsonGenerator.java:50) ~[jira-rest-java-client-core-5.2.2.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.gen.IssueInputJsonGenerator.generate(IssueInputJsonGenerator.java:43) ~[jira-rest-java-client-core-5.2.2.jar!/:na]
at com.atlassian.jira.rest.client.internal.json.gen.IssueInputJsonGenerator.generate(IssueInputJsonGenerator.java:31) ~[jira-rest-java-client-core-5.2.2.jar!/:na]

is there some other approach, or other Map, that I could use?

Thank you in advance.

Hi @Dominik1

It seems to work for me using List<Map<String, Object>>. I give you the code used to test it.

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CustomFieldExample {
    public static void main(String[] args) {
        String json = "{\n" +
                "  \"customfield_22133\": [\n" +
                "    {\"value0\": \"Customer\"},\n" +
                "    {\"value1\": \"Partner\"},\n" +
                "    {\"value2\": \"Internal\"}\n" +
                "  ]\n" +
                "}";

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            CustomFieldWrapper customFieldWrapper = objectMapper.readValue(json, CustomFieldWrapper.class);
            System.out.println(customFieldWrapper);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

class CustomFieldWrapper {
    private List<CustomField> customfield_22133;

    public CustomFieldWrapper() {
        this.customfield_22133 = new ArrayList<>();
    }

    public List<CustomField> getCustomfield_22133() {
        return customfield_22133;
    }

    public void setCustomfield_22133(List<CustomField> customfield_22133) {
        this.customfield_22133 = customfield_22133;
    }

    @Override
    public String toString() {
        return "CustomFieldWrapper{" +
                "customfield_22133=" + customfield_22133 +
                '}';
    }
}

class CustomField {
    private Map<String, Object> values = new HashMap<>();

    @JsonAnySetter
    public void setValues(String key, Object value) {
        values.put(key, value);
    }

    public Map<String, Object> getValues() {
        return values;
    }

    @Override
    public String toString() {
        return "CustomField{" +
                "values=" + values +
                '}';
    }
}

Hi @FabienPenchenat thanks for your suggestion. At it’s core, my solution was the same, (without all the customField objects.

A colleague suggested a solustion, which worked for me. (And a suggestion for anybody, who will encounter this issue in the future).

I’ve created a List in which I have the map… since for some reason jira’s own issueInputJsonGenerator cannot handle Maps, but it can handle ComplexIssueInputFields, which have Maps…

so basically this code works

List<ComplexIssueInputFieldValue> fieldInputs = new ArrayList<>();

                    for (IssueFieldValue child : root.getDirectChildren()) {
                        Map<String, Object> fromComplexChildren = createFromComplexChildren(child, parameterMap);
                        fieldInputs.add(new ComplexIssueInputFieldValue(fromComplexChildren));
                    }
                    builder.setFieldInput(new FieldInput(root.getFieldName(), fieldInputs));

Note: builder is only issueInputBuilder()

IssueInputBuilder builder = new IssueInputBuilder();