DATAES-920 - Add parameter to @Field annotation to store null values.

Original PR: #516
This commit is contained in:
Peter-Josef Meisch
2020-09-07 22:24:17 +02:00
committed by GitHub
parent ef1cbc35f6
commit d03510528b
5 changed files with 68 additions and 9 deletions

View File

@@ -39,6 +39,7 @@ import java.util.Map;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
@@ -616,7 +617,7 @@ public class MappingElasticsearchConverterUnitTests {
assertEquals(expected, json, false);
}
@Test
@Test // DATAES-716
void shouldReadLocalDate() {
Document document = Document.create();
document.put("id", "4711");
@@ -813,6 +814,25 @@ public class MappingElasticsearchConverterUnitTests {
assertEquals(expected, document.toJson(), false);
}
@Test // DATAES-920
@DisplayName("should write null value if configured")
void shouldWriteNullValueIfConfigured() throws JSONException {
EntityWithNullField entity = new EntityWithNullField();
entity.setId("42");
String expected = "{\n" + //
" \"id\": \"42\",\n" + //
" \"saved\": null\n" + //
"}\n"; //
Document document = Document.create();
mappingElasticsearchConverter.write(entity, document);
assertEquals(expected, document.toJson(), false);
}
private String pointTemplate(String name, Point point) {
return String.format(Locale.ENGLISH, "\"%s\":{\"lat\":%.1f,\"lon\":%.1f}", name, point.getX(), point.getY());
}
@@ -1046,4 +1066,11 @@ public class MappingElasticsearchConverterUnitTests {
@Id private String id;
private Object content;
}
@Data
static class EntityWithNullField {
@Id private String id;
@Field(type = FieldType.Text) private String notSaved;
@Field(type = FieldType.Text, storeNullValue = true) private String saved;
}
}