Skip to content

Fix #6261: honor @JsonView on properties-based Enum Creator parameters - #6250

Open
pjfanning wants to merge 3 commits into
FasterXML:2.18from
pjfanning:enum-creator-json-view
Open

pjfanning wants to merge 3 commits into
FasterXML:2.18from
pjfanning:enum-creator-json-view

Conversation

@pjfanning

@pjfanning pjfanning commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

(note: fixes #6261)

@JsonView on the parameters of a properties-based @JsonCreator of an Enum was ignored: every parameter was passed to the factory regardless of the active view. POJO Creator parameters already honor views.

enum Level {
    LOW, HIGH;

    @JsonCreator
    static Level create(@JsonProperty("name") @JsonView(ViewA.class) String name,
                        @JsonProperty("note") @JsonView(ViewB.class) String note) { ... }
}

mapper.readerWithView(ViewA.class).forType(Level.class)
    .readValue("{\"name\":\"low\",\"note\":\"x\"}");
// before: note == "x"; after: note == null (same as for a POJO Creator)

Changes

  • BasicDeserializerFactory.createEnumDeserializer() now assigns views to the Enum Creator properties. Previously none were set, so visibleInView() was always true.
  • FactoryBasedEnumDeserializer.deserializeEnumUsingPropertyBased() skips Creator parameters that are not visible in the active view, the same way BeanDeserializer does for POJO Creator properties.

Tradeoff

Only explicit @JsonView annotations count: one on the parameter, or else one on the Enum type. With DEFAULT_VIEW_INCLUSION disabled, parameters without @JsonView stay visible. POJO Creator properties would be hidden in that case. I stopped short of matching that on a patch branch, because it would change results for existing Enums whose Creator parameters have no @JsonView.

Tests

Added ViewsWithEnumCreatorTest, covering views on parameters (with DEFAULT_VIEW_INCLUSION both enabled and disabled), a view on the Enum type, and a Creator without views (behavior unchanged). Without the fix, 2 of its 3 tests fail. ./mvnw verify on JDK 17 has one failure, DateSerializationTest.testWithTimeZoneOverride (PST vs GMT-08:00). It is caused by the local JDK's time zone names and also fails without this change.

🤖 Generated with Claude Code

pjfanning and others added 2 commits September 29, 2026 11:54
Views on parameters of a properties-based `@JsonCreator` of an Enum were
ignored, so all parameters were passed regardless of the active view --
unlike Creator parameters of POJOs. Views of such parameters are now
assigned (explicit `@JsonView` on the parameter, or on the Enum type)
and parameters not visible in the active view are skipped.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cowtowncoder cowtowncoder linked an issue Oct 1, 2026 that may be closed by this pull request
@cowtowncoder

Copy link
Copy Markdown
Member

I don't think this qualifies for 2.18 inclusion, let's go via 2.x (which does get merged to 3.1)

@cowtowncoder cowtowncoder changed the title Honor @JsonView on properties-based Enum Creator parameters Fix #6261: honor @JsonView on properties-based Enum Creator parameters Oct 1, 2026
@gitar-bot

gitar-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
CI failed: Fuzzer build failure in OSS-Fuzz due to an outdated package import in the fuzzer test matching a different major version namespace.

Overview

1 log analyzed showing a failure during fuzzer compilation in the OSS-Fuzz job due to mismatched package imports.

Failures

OSS-Fuzz Compilation Failure (confidence: high)

  • Type: tooling
  • Affected jobs: 110209101746
  • Related to change: no
  • Root cause: The fuzzer imports tools.jackson.databind.ObjectMapper, but the current branch builds jackson-databind under the com.fasterxml.jackson.databind package namespace.
  • Suggested fix: Update the OSS-Fuzz fuzzer source code or integration configuration to use the package namespace corresponding to the target branch version.

Summary

  • Change-related failures: 0
  • Infrastructure/flaky failures: 1 (OSS-Fuzz build tooling failure)
  • Recommended action: Review and update the OSS-Fuzz integration configuration for this branch, as the failure is unrelated to the PR code changes.
Code Review ✅ Approved

🟡 Medium risk · Enum creator deserialization now skips parameters hidden by the active view.

Fixes @JsonView on properties-based Enum Creator parameters to match POJO Creator behavior: parameters outside the active view are now skipped instead of always passed to the factory. No issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support @JsonView on properties-based Enum Creator parameters

2 participants