Skip to content

Commit 85366ad

Browse files
authored
PR for JsonApplyView (#78) (#338)
1 parent bdf79ad commit 85366ad

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate
1616

1717
2.22 (not yet released)
1818

19+
#78: Add `@JsonApplyView` to allow changing active JsonView on submodels
20+
(requested by Michael I)
21+
(contributed by @f-aubert)
1922
#339: Add `OptBoolean` valued property "order" in `@JsonIncludeProperties`
2023
#342: Add `@JsonTypeInfo.writeTypeIdForDefaultImpl` to allow skipping
2124
writing of type id for values of default type
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.fasterxml.jackson.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Annotation used for specifying view that should be used to process
10+
* the property that is defined by method or field annotated.
11+
*<p>
12+
* An example annotation would be:
13+
*<pre>
14+
* &#064;JsonApplyView(BasicView.class)
15+
* public MyValue value;
16+
*</pre>
17+
* which would specify that property annotated would be processed
18+
* using View identified by {@code BasicView.class}.
19+
*<p>
20+
* Note: initially processing only covers serialization.
21+
*
22+
* @since 2.22
23+
*/
24+
@Target({ElementType.ANNOTATION_TYPE,
25+
ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})
26+
@Retention(RetentionPolicy.RUNTIME)
27+
@JacksonAnnotation
28+
public @interface JsonApplyView
29+
{
30+
/**
31+
* View that should be used to process annotated property, if any;
32+
* special value {@link JsonApplyView.NONE} indicates that no View
33+
* should used.
34+
*/
35+
public Class<?> value() default NONE.class;
36+
37+
/**
38+
* Special view indicating no views should be used for processing annotated property.
39+
*/
40+
static public interface NONE {}
41+
}

0 commit comments

Comments
 (0)