-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathJsonNullableModule.java
More file actions
55 lines (46 loc) · 1.7 KB
/
JsonNullableModule.java
File metadata and controls
55 lines (46 loc) · 1.7 KB
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
51
52
53
54
55
package org.openapitools.jackson.nullable;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.databind.Module;
public class JsonNullableModule extends Module {
private final String NAME = "JsonNullableModule";
private boolean mapBlankStringToNull = false;
/**
* Configures whether blank strings (e.g. {@code ""}, {@code " "}) deserialized into
* non-String {@code JsonNullable} fields are mapped to {@code JsonNullable.of(null)}
* instead of {@code JsonNullable.undefined()}.
*
* <p>This is relevant for PATCH semantics: a blank string sent by a client expresses
* explicit intent to clear a value, which {@code undefined()} silently swallows.
*
* <p>Default is {@code false} for backwards compatibility.
*/
public JsonNullableModule mapBlankStringToNull(boolean state) {
this.mapBlankStringToNull = state;
return this;
}
@Override
public void setupModule(SetupContext context) {
context.addSerializers(new JsonNullableSerializers());
context.addDeserializers(new JsonNullableDeserializers(mapBlankStringToNull));
// Modify type info for JsonNullable
context.addTypeModifier(new JsonNullableTypeModifier());
context.addBeanSerializerModifier(new JsonNullableBeanSerializerModifier());
}
@Override
public Version version() {
return PackageVersion.VERSION;
}
@Override
public int hashCode() {
return NAME.hashCode();
}
@Override
public boolean equals(Object o) {
return this == o;
}
@Override
public String getModuleName() {
return NAME;
}
}