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 new file mode 100644 index 00000000..b3a78cac --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/annotation/JsonApplyView.java @@ -0,0 +1,41 @@ +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 + * 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 + * 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 +{ + /** + * 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 for processing annotated property. + */ + static public interface NONE {} +}