use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldReadListOfLocalDate.
// DATAES-924
@Test
@DisplayName("should read list of LocalDate")
void shouldReadListOfLocalDate() {
Document document = Document.create();
document.put("id", "4711");
document.put("dates", new String[] { "15.09.2020", "01.05.2019" });
LocalDatesEntity entity = mappingElasticsearchConverter.read(LocalDatesEntity.class, document);
assertThat(entity.getId()).isEqualTo("4711");
assertThat(entity.getDates()).hasSize(2).containsExactly(LocalDate.of(2020, 9, 15), LocalDate.of(2019, 5, 1));
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldReadUsingValueConverters.
// #1945
@Test
@DisplayName("should read using ValueConverters")
void shouldReadUsingValueConverters() throws JSONException {
String json = //
"{\n" + //
" \"id\": \"42\",\n" + //
" \"fieldWithClassBasedConverter\": \"desabssalc\",\n" + //
" \"fieldWithEnumBasedConverter\": \"desabmune\",\n" + //
" \"dontConvert\": \"Monty Python's Flying Circus\"\n" + //
"}\n";
Document source = Document.parse(json);
// when
EntityWithCustomValueConverters entity = mappingElasticsearchConverter.read(EntityWithCustomValueConverters.class, source);
assertThat(entity.getId()).isEqualTo("42");
assertThat(entity.getFieldWithClassBasedConverter()).isEqualTo("classbased");
assertThat(entity.getFieldWithEnumBasedConverter()).isEqualTo("enumbased");
assertThat(entity.getDontConvert()).isEqualTo("Monty Python's Flying Circus");
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method readGenericMap.
// DATAES-530
@Test
public void readGenericMap() {
Document source = Document.create();
source.put("objectMap", Collections.singletonMap("glock19", gunAsMap));
Skynet target = mappingElasticsearchConverter.read(Skynet.class, source);
assertThat(target.getObjectMap()).containsEntry("glock19", gun);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldNotWriteTypeHintsIfNotConfigured.
// #1454
@Test
@DisplayName("should not write type hints if configured")
void shouldNotWriteTypeHintsIfNotConfigured() throws JSONException {
((SimpleElasticsearchMappingContext) mappingElasticsearchConverter.getMappingContext()).setWriteTypeHints(false);
PersonWithCars person = new PersonWithCars();
person.setId("42");
person.setName("Smith");
Car car1 = new Car();
car1.setModel("Ford Mustang");
Car car2 = new ElectricCar();
car2.setModel("Porsche Taycan");
person.setCars(Arrays.asList(car1, car2));
String expected = //
"{\n" + //
" \"id\": \"42\",\n" + //
" \"name\": \"Smith\",\n" + //
" \"cars\": [\n" + //
" {\n" + //
" \"model\": \"Ford Mustang\"\n" + //
" },\n" + //
" {\n" + //
" \"model\": \"Porsche Taycan\"\n" + //
" }\n" + //
" ]\n" + //
"}\n";
Document document = Document.create();
mappingElasticsearchConverter.write(person, document);
assertEquals(expected, document.toJson(), true);
}
use of org.springframework.data.elasticsearch.core.document.Document in project spring-data-elasticsearch by spring-projects.
the class MappingElasticsearchConverterUnitTests method shouldWriteEntityWithMapAsObject.
// DATAES-865
@Test
void shouldWriteEntityWithMapAsObject() throws JSONException {
Map<String, Object> map = new LinkedHashMap<>();
map.put("foo", "bar");
EntityWithObject entity = new EntityWithObject();
entity.setId("42");
entity.setContent(map);
String expected = //
"{\n" + //
" \"id\": \"42\",\n" + //
" \"content\": {\n" + //
" \"foo\": \"bar\"\n" + //
" }\n" + //
"}\n";
Document document = Document.create();
mappingElasticsearchConverter.write(entity, document);
assertEquals(expected, document.toJson(), false);
}
Aggregations