14
14
*/
15
15
package com .norconex .commons .lang .flow .module ;
16
16
17
+ import static java .util .Optional .ofNullable ;
18
+
17
19
import java .io .IOException ;
18
20
import java .util .function .Consumer ;
19
21
24
26
import com .fasterxml .jackson .databind .JsonMappingException ;
25
27
import com .fasterxml .jackson .databind .deser .ContextualDeserializer ;
26
28
import com .fasterxml .jackson .databind .deser .ResolvableDeserializer ;
29
+ import com .norconex .commons .lang .ClassUtil ;
27
30
import com .norconex .commons .lang .flow .FlowMapperConfig ;
28
31
import com .norconex .commons .lang .flow .JsonFlow ;
32
+ import com .norconex .commons .lang .flow .JsonFlow .NoBuilder ;
29
33
30
34
import lombok .Data ;
31
35
import lombok .RequiredArgsConstructor ;
@@ -42,6 +46,7 @@ public class FlowDeserializer<T> extends JsonDeserializer<Consumer<T>>
42
46
43
47
private final FlowMapperConfig config ;
44
48
private final JsonDeserializer <?> defaultDeserializer ;
49
+ private final ThreadLocal <FlowMapperConfig > propCfg = new ThreadLocal <>();
45
50
46
51
@ SuppressWarnings ("unchecked" )
47
52
private RootHandler <T > rootHandler =
@@ -50,7 +55,8 @@ public class FlowDeserializer<T> extends JsonDeserializer<Consumer<T>>
50
55
@ Override
51
56
public Consumer <T > deserialize (JsonParser p , DeserializationContext ctx )
52
57
throws IOException {
53
- return rootHandler .read (new FlowDeserContext (config , p ));
58
+ return rootHandler .read (new FlowDeserContext (
59
+ ofNullable (propCfg .get ()).orElse (config ), p ));
54
60
}
55
61
56
62
@ Override
@@ -60,8 +66,19 @@ public JsonDeserializer<?> createContextual(
60
66
if (property == null ) {
61
67
return defaultDeserializer ;
62
68
}
63
- return property .getAnnotation (JsonFlow .class ) == null
64
- ? defaultDeserializer : this ;
69
+ var flowAnnot = property .getAnnotation (JsonFlow .class );
70
+ if (flowAnnot == null ) {
71
+ return defaultDeserializer ;
72
+ }
73
+
74
+ // If needed, create property-specific flow mapper config
75
+ var supplier = flowAnnot .builder ();
76
+ if (supplier .equals (NoBuilder .class )) {
77
+ propCfg .remove ();
78
+ } else {
79
+ propCfg .set (ClassUtil .newInstance (supplier ).get ());
80
+ }
81
+ return this ;
65
82
}
66
83
67
84
@ Override
0 commit comments