Skip to content

fix(custom-fields): preserve JSON objects/arrays in --custom values#976

Open
Hernanduno wants to merge 2 commits intoankitpokhrel:mainfrom
Hernanduno:codex/fix-custom-user-picker-object-serialization
Open

fix(custom-fields): preserve JSON objects/arrays in --custom values#976
Hernanduno wants to merge 2 commits intoankitpokhrel:mainfrom
Hernanduno:codex/fix-custom-user-picker-object-serialization

Conversation

@Hernanduno
Copy link
Copy Markdown

Problem

Custom fields provided via --custom were always treated as plain strings in key paths that needed structured payloads. This broke User Picker fields (single and multi) and other custom fields requiring nested objects because Jira expected a JSON object/array, not an escaped string.

Motivation

Users editing issues with commands like the one below would hit Jira validation errors even when passing valid JSON.

Example command (values anonymized)

jira issue edit DEMO-16216 --custom 'code-reviewer={"name":"redacted.user@example.com"}' --no-input

Before this fix (internal payload sent)

"customfield_xxxxx": [{"set": "{"name":"redacted.user@example.com"}"}]

After this fix (internal payload sent)

"customfield_xxxxx": [{"set": {"name": "redacted.user@example.com"}}]

What changed

  • Added a dedicated parser in pkg/jira/customfield_parser.go that detects JSON containers (object/array) and unmarshals them while preserving existing behavior for non-container primitives/strings.

  • Wired create flow to pass parsed object/array directly into fields payload (instead of forcing string).

  • Wired edit flow to emit set operations with any typed value (object/array) so Jira receives correct structured JSON.

  • Kept pkg/jira/customfield.go focused on type declarations; parser logic is now isolated in its own file.

Testing

  • Added unit tests in pkg/jira/customfield_json_test.go for create and edit with deeply nested JSON structures.

  • Verified with: go test ./pkg/jira

jose antonio hernandez hernandez added 2 commits April 2, 2026 22:40
Problem

Custom fields provided via --custom were always treated as plain strings in key paths that needed structured payloads. This broke User Picker fields (single and multi) and other custom fields requiring nested objects because Jira expected a JSON object/array, not an escaped string.

Motivation

Users editing issues with commands like the one below would hit Jira validation errors even when passing valid JSON.

Example command (values anonymized)

jira issue edit DEMOSERVICES-16216 --custom 'code-reviewer={"name":"redacted.user@example.com"}' --no-input

Before this fix (internal payload sent)

"customfield_xxxxx": [{"set": "{\"name\":\"redacted.user@example.com\"}"}]

After this fix (internal payload sent)

"customfield_xxxxx": [{"set": {"name": "redacted.user@example.com"}}]

What changed

- Added a dedicated parser in pkg/jira/customfield_parser.go that detects JSON containers (object/array) and unmarshals them while preserving existing behavior for non-container primitives/strings.

- Wired create flow to pass parsed object/array directly into fields payload (instead of forcing string).

- Wired edit flow to emit set operations with any typed value (object/array) so Jira receives correct structured JSON.

- Kept pkg/jira/customfield.go focused on type declarations; parser logic is now isolated in its own file.

Testing

- Added unit tests in pkg/jira/customfield_json_test.go for create and edit with deeply nested JSON structures.

- Verified with: go test ./pkg/jira
Replace negated OR condition with equivalent De Morgan form to satisfy golangci-lint/staticcheck in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant