18
18
import static org .skyscreamer .jsonassert .JSONAssert .*;
19
19
import static org .springframework .data .elasticsearch .annotations .FieldType .*;
20
20
21
+ import org .springframework .data .elasticsearch .annotations .FieldType ;
22
+ import org .springframework .data .elasticsearch .annotations .InnerField ;
23
+ import org .springframework .data .elasticsearch .annotations .MultiField ;
21
24
import reactor .core .publisher .Mono ;
22
25
import reactor .core .scheduler .Schedulers ;
23
26
24
27
import java .time .Instant ;
28
+ import java .util .List ;
25
29
26
30
import org .json .JSONException ;
27
31
import org .junit .jupiter .api .DisplayName ;
@@ -78,6 +82,40 @@ void shouldWriteRuntimeFields() throws JSONException {
78
82
79
83
assertEquals (expected , mapping , true );
80
84
}
85
+
86
+ @ Test // #2952
87
+ void shouldMapNullityParameters () throws JSONException {
88
+ // Given
89
+ ReactiveMappingBuilder mappingBuilder = getReactiveMappingBuilder ();
90
+ String expected = """
91
+ {
92
+ "properties": {
93
+ "_class": {
94
+ "type": "keyword",
95
+ "index": false,
96
+ "doc_values": false
97
+ },
98
+ "empty-field": {
99
+ "type": "keyword",
100
+ "null_value": "EMPTY",
101
+ "fields": {
102
+ "suffix": {
103
+ "type": "keyword",
104
+ "null_value": "EMPTY_TEXT"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ """ ;
111
+
112
+ // When
113
+ String result = Mono .defer (() -> mappingBuilder .buildReactivePropertyMapping (MultiFieldWithNullEmptyParameters .class ))
114
+ .subscribeOn (Schedulers .parallel ()).block ();
115
+
116
+ // Then
117
+ assertEquals (expected , result , true );
118
+ }
81
119
82
120
// region entities
83
121
@ Document (indexName = "runtime-fields" )
@@ -88,5 +126,14 @@ private static class RuntimeFieldEntity {
88
126
@ Field (type = Date , format = DateFormat .epoch_millis , name = "@timestamp" )
89
127
@ Nullable private Instant timestamp ;
90
128
}
129
+
130
+ @ SuppressWarnings ("unused" )
131
+ private static class MultiFieldWithNullEmptyParameters {
132
+ @ Nullable
133
+ @ MultiField (
134
+ mainField = @ Field (name = "empty-field" , type = FieldType .Keyword , nullValue = "EMPTY" , storeNullValue = true ),
135
+ otherFields = {
136
+ @ InnerField (suffix = "suffix" , type = Keyword , nullValue = "EMPTY_TEXT" ) }) private List <String > emptyField ;
137
+ }
91
138
// endregion
92
139
}
0 commit comments