|
39 | 39 | import org.springframework.data.elasticsearch.core.document.SearchDocument;
|
40 | 40 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
41 | 41 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
42 |
| -import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentPropertyConverter; |
| 42 | +import org.springframework.data.elasticsearch.core.mapping.PropertyValueConverter; |
43 | 43 | import org.springframework.data.elasticsearch.core.query.Criteria;
|
44 | 44 | import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
45 | 45 | import org.springframework.data.elasticsearch.core.query.FetchSourceFilter;
|
@@ -425,8 +425,9 @@ protected <R> R readValue(@Nullable Object value, ElasticsearchPersistentPropert
|
425 | 425 |
|
426 | 426 | Class<?> rawType = type.getType();
|
427 | 427 |
|
428 |
| - if (property.hasPropertyConverter()) { |
429 |
| - value = propertyConverterRead(property, value); |
| 428 | + if (property.hasPropertyValueConverter()) { |
| 429 | + // noinspection unchecked |
| 430 | + return (R) propertyConverterRead(property, value); |
430 | 431 | } else if (TemporalAccessor.class.isAssignableFrom(property.getType())
|
431 | 432 | && !conversions.hasCustomReadTarget(value.getClass(), rawType)) {
|
432 | 433 |
|
@@ -466,27 +467,27 @@ private <T> T readValue(Object value, TypeInformation<?> type) {
|
466 | 467 | }
|
467 | 468 |
|
468 | 469 | private Object propertyConverterRead(ElasticsearchPersistentProperty property, Object source) {
|
469 |
| - ElasticsearchPersistentPropertyConverter propertyConverter = Objects |
470 |
| - .requireNonNull(property.getPropertyConverter()); |
| 470 | + PropertyValueConverter propertyValueConverter = Objects.requireNonNull(property.getPropertyValueConverter()); |
471 | 471 |
|
472 | 472 | if (source instanceof String[]) {
|
473 | 473 | // convert to a List
|
474 | 474 | source = Arrays.asList((String[]) source);
|
475 | 475 | }
|
476 | 476 |
|
477 | 477 | if (source instanceof List) {
|
478 |
| - source = ((List<?>) source).stream().map(it -> convertOnRead(propertyConverter, it)) |
| 478 | + source = ((List<?>) source).stream().map(it -> convertOnRead(propertyValueConverter, it)) |
479 | 479 | .collect(Collectors.toList());
|
480 | 480 | } else if (source instanceof Set) {
|
481 |
| - source = ((Set<?>) source).stream().map(it -> convertOnRead(propertyConverter, it)).collect(Collectors.toSet()); |
| 481 | + source = ((Set<?>) source).stream().map(it -> convertOnRead(propertyValueConverter, it)) |
| 482 | + .collect(Collectors.toSet()); |
482 | 483 | } else {
|
483 |
| - source = convertOnRead(propertyConverter, source); |
| 484 | + source = convertOnRead(propertyValueConverter, source); |
484 | 485 | }
|
485 | 486 | return source;
|
486 | 487 | }
|
487 | 488 |
|
488 |
| - private Object convertOnRead(ElasticsearchPersistentPropertyConverter propertyConverter, Object source) { |
489 |
| - return propertyConverter.read(source); |
| 489 | + private Object convertOnRead(PropertyValueConverter propertyValueConverter, Object source) { |
| 490 | + return propertyValueConverter.read(source); |
490 | 491 | }
|
491 | 492 |
|
492 | 493 | /**
|
@@ -897,7 +898,7 @@ private void writeProperties(ElasticsearchPersistentEntity<?> entity, Persistent
|
897 | 898 | continue;
|
898 | 899 | }
|
899 | 900 |
|
900 |
| - if (property.hasPropertyConverter()) { |
| 901 | + if (property.hasPropertyValueConverter()) { |
901 | 902 | value = propertyConverterWrite(property, value);
|
902 | 903 | sink.set(property, value);
|
903 | 904 | } else if (TemporalAccessor.class.isAssignableFrom(property.getActualType())
|
@@ -1070,15 +1071,14 @@ private Object getPotentiallyConvertedSimpleWrite(@Nullable Object value, @Nulla
|
1070 | 1071 | }
|
1071 | 1072 |
|
1072 | 1073 | private Object propertyConverterWrite(ElasticsearchPersistentProperty property, Object value) {
|
1073 |
| - ElasticsearchPersistentPropertyConverter propertyConverter = Objects |
1074 |
| - .requireNonNull(property.getPropertyConverter()); |
| 1074 | + PropertyValueConverter propertyValueConverter = Objects.requireNonNull(property.getPropertyValueConverter()); |
1075 | 1075 |
|
1076 | 1076 | if (value instanceof List) {
|
1077 |
| - value = ((List<?>) value).stream().map(propertyConverter::write).collect(Collectors.toList()); |
| 1077 | + value = ((List<?>) value).stream().map(propertyValueConverter::write).collect(Collectors.toList()); |
1078 | 1078 | } else if (value instanceof Set) {
|
1079 |
| - value = ((Set<?>) value).stream().map(propertyConverter::write).collect(Collectors.toSet()); |
| 1079 | + value = ((Set<?>) value).stream().map(propertyValueConverter::write).collect(Collectors.toSet()); |
1080 | 1080 | } else {
|
1081 |
| - value = propertyConverter.write(value); |
| 1081 | + value = propertyValueConverter.write(value); |
1082 | 1082 | }
|
1083 | 1083 | return value;
|
1084 | 1084 | }
|
@@ -1252,18 +1252,18 @@ private void updateCriteria(Criteria criteria, ElasticsearchPersistentEntity<?>
|
1252 | 1252 |
|
1253 | 1253 | if (persistentProperty != null) {
|
1254 | 1254 |
|
1255 |
| - if (persistentProperty.hasPropertyConverter()) { |
1256 |
| - ElasticsearchPersistentPropertyConverter propertyConverter = Objects |
1257 |
| - .requireNonNull(persistentProperty.getPropertyConverter()); |
| 1255 | + if (persistentProperty.hasPropertyValueConverter()) { |
| 1256 | + PropertyValueConverter propertyValueConverter = Objects |
| 1257 | + .requireNonNull(persistentProperty.getPropertyValueConverter()); |
1258 | 1258 | criteria.getQueryCriteriaEntries().forEach(criteriaEntry -> {
|
1259 | 1259 | Object value = criteriaEntry.getValue();
|
1260 | 1260 | if (value.getClass().isArray()) {
|
1261 | 1261 | Object[] objects = (Object[]) value;
|
1262 | 1262 | for (int i = 0; i < objects.length; i++) {
|
1263 |
| - objects[i] = propertyConverter.write(objects[i]); |
| 1263 | + objects[i] = propertyValueConverter.write(objects[i]); |
1264 | 1264 | }
|
1265 | 1265 | } else {
|
1266 |
| - criteriaEntry.setValue(propertyConverter.write(value)); |
| 1266 | + criteriaEntry.setValue(propertyValueConverter.write(value)); |
1267 | 1267 | }
|
1268 | 1268 | });
|
1269 | 1269 | }
|
|
0 commit comments