aboutsummaryrefslogtreecommitdiff
path: root/website/templates/features/experimental/Jacksonized.html
blob: b3a138644b26d76beb9008af879db892c5124961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<#import "../_features.html" as f>

<@f.scaffold title="@Jacksonized" logline="Bob, meet Jackson. Lets make sure you become fast friends.">
	<@f.history>
		<p>
			<code>@Jacksonized</code> was introduced as experimental feature in lombok v1.18.14.
		</p>
	</@f.history>
	
	<@f.overview>
		<p>
			The <code>@Jacksonized</code> annotation is an add-on annotation for <a href="/features/Builder"><code>@Builder</code></a> and <a href="/features/experimental/SuperBuilder"><code>@SuperBuilder</code></a>.
			It automatically configures the generated builder class to be used by <a href="https://github.com/FasterXML/jackson">Jackson</a>'s deserialization.
			It only has an effect if present at a context where there is also a <code>@Builder</code> or a <code>@SuperBuilder</code>; a warning is emitted otherwise.
 		</p><p>
			Without <code>@Jacksonized</code>, you would have to customize your builder class(es).
			With <code>@Jacksonized</code>, you can simply write something like this to let Jackson use the generated builder:<div class="snippet"><div class="java" align="left"><pre>
@Jacksonized @Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class JacksonExample {
	private List&lt;Foo&gt; foos;
}
</pre></div></div>
 		</p><p>
			This annotation does <em>not</em> change the behavior of the generated builder.
			A <code>@Jacksonized</code> <code>@SuperBuilder</code> remains fully compatible to regular <code>@SuperBuilder</code>s.
		</p>
	</@f.overview>
	
	<@f.smallPrint>
 		<p>
			In particular, the annotation does the following:
			<ul>
				<li>
					Configure Jackson to use the builder for deserialization using <code>@JsonDeserialize(builder=<em>Foobar</em>.<em>Foobar</em>Builder[Impl].class))</code> on the class (where <em>Foobar</em> is the name of the annotated class, and <code>Impl</code> is added for <code>@SuperBuilder</code>).
					(An error is emitted if such an annotation already exists.)
				</li><li>
					Copy Jackson-related configuration annotations (like <code>@JsonIgnoreProperties</code>) from the class to the builder class.
					This is necessary so that Jackson recognizes them when using the builder.
				</li><li>
					Insert <code>@JsonPOJOBuilder(withPrefix="")</code> on the generated builder class to override Jackson's default prefix "with".
					If you configured a different prefix in lombok using <code>setterPrefix</code>, this value is used.
					If you changed the name of the <code>build()</code> method using <code>buildMethodName</code>, this is also made known to Jackson.
				</li><li>
					For <code>@SuperBuilder</code>, make the builder implementation class package-private.
				</li>
			</ul>
		</p>
	</@f.smallPrint>
</@f.scaffold>