From d107a0872243cfff04f114489e653821ef1f46de Mon Sep 17 00:00:00 2001 From: isc-auf Date: Mon, 9 Mar 2026 17:57:51 +0100 Subject: [PATCH 1/2] Fix #78: new JsonApplyView annotation --- .../jackson/annotation/JsonApplyView.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java b/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java new file mode 100644 index 00000000..2a96ba8e --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java @@ -0,0 +1,34 @@ +package com.fasterxml.jackson.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used for specifying view that should be used to + * process (serialize) the property that is defined by method + * or field annotated. + *

+ * An example annotation would be: + *

+ *  @JsonApplyView(BasicView.class)
+ *
+ * which would specify that property annotated would be processed + * (serialized) using View identified by BasicView.class. + */ +@Target({ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@JacksonAnnotation +public @interface JsonApplyView { + /** + * View that should be used to serialize annotated property. + */ + public Class value() default NONE.class; + + /** + * Special view indicating no views should be used to serialize annotated property. + */ + static public interface NONE {} +} From 178fe280ecaef1846675f569771ea69a1d17966e Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 18 Apr 2026 14:55:50 -0700 Subject: [PATCH 2/2] Minor tweaks to Javadocs --- release-notes/VERSION-2.x | 3 +++ .../jackson/annotation/JsonApplyView.java | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index d850e3f0..5464a3af 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,6 +16,9 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate 2.22 (not yet released) +#78: Add `@JsonApplyView` to allow changing active JsonView on submodels + (requested by Michael I) + (contributed by @f-aubert) #339: Add `OptBoolean` valued property "order" in `@JsonIncludeProperties` #342: Add `@JsonTypeInfo.writeTypeIdForDefaultImpl` to allow skipping writing of type id for values of default type diff --git a/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java b/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java index 2a96ba8e..b3a78cac 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java @@ -6,29 +6,36 @@ import java.lang.annotation.Target; /** - * Annotation used for specifying view that should be used to - * process (serialize) the property that is defined by method - * or field annotated. + * Annotation used for specifying view that should be used to process + * the property that is defined by method or field annotated. *

* An example annotation would be: *

  *  @JsonApplyView(BasicView.class)
+ *  public MyValue value;
  *
* which would specify that property annotated would be processed - * (serialized) using View identified by BasicView.class. + * using View identified by {@code BasicView.class}. + *

+ * Note: initially processing only covers serialization. + * + * @since 2.22 */ @Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @JacksonAnnotation -public @interface JsonApplyView { +public @interface JsonApplyView +{ /** - * View that should be used to serialize annotated property. + * View that should be used to process annotated property, if any; + * special value {@link JsonApplyView.NONE} indicates that no View + * should used. */ public Class value() default NONE.class; /** - * Special view indicating no views should be used to serialize annotated property. + * Special view indicating no views should be used for processing annotated property. */ static public interface NONE {} }