|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.core.convert;
|
17 | 17 |
|
18 |
| -import static org.springframework.data.convert.ConverterBuilder.*; |
| 18 | +import static org.springframework.data.convert.ConverterBuilder.reading; |
19 | 19 |
|
20 | 20 | import java.math.BigDecimal;
|
21 | 21 | import java.math.BigInteger;
|
|
27 | 27 | import java.util.Collection;
|
28 | 28 | import java.util.Currency;
|
29 | 29 | import java.util.List;
|
| 30 | +import java.util.Set; |
30 | 31 | import java.util.UUID;
|
31 | 32 | import java.util.concurrent.atomic.AtomicInteger;
|
32 | 33 | import java.util.concurrent.atomic.AtomicLong;
|
|
47 | 48 | import org.bson.types.Code;
|
48 | 49 | import org.bson.types.Decimal128;
|
49 | 50 | import org.bson.types.ObjectId;
|
50 |
| - |
51 | 51 | import org.springframework.core.convert.ConversionFailedException;
|
52 | 52 | import org.springframework.core.convert.TypeDescriptor;
|
53 | 53 | import org.springframework.core.convert.converter.ConditionalConverter;
|
| 54 | +import org.springframework.core.convert.converter.ConditionalGenericConverter; |
54 | 55 | import org.springframework.core.convert.converter.Converter;
|
55 | 56 | import org.springframework.core.convert.converter.ConverterFactory;
|
56 | 57 | import org.springframework.data.convert.ReadingConverter;
|
|
60 | 61 | import org.springframework.data.mongodb.core.mapping.MongoVector;
|
61 | 62 | import org.springframework.data.mongodb.core.query.Term;
|
62 | 63 | import org.springframework.data.mongodb.core.script.NamedMongoScript;
|
| 64 | +import org.springframework.lang.Nullable; |
63 | 65 | import org.springframework.util.Assert;
|
64 | 66 | import org.springframework.util.NumberUtils;
|
65 | 67 | import org.springframework.util.StringUtils;
|
@@ -473,6 +475,36 @@ public Vector convert(BinaryVector source) {
|
473 | 475 | }
|
474 | 476 | }
|
475 | 477 |
|
| 478 | +// @WritingConverter |
| 479 | +// enum BytesToBinaryVectorConverter implements ConditionalGenericConverter { |
| 480 | +// INSTANCE; |
| 481 | +// |
| 482 | +// @Nullable |
| 483 | +// public BinaryVector convert(byte[] source) { |
| 484 | +// return BinaryVector.int8Vector(source); |
| 485 | +// } |
| 486 | +// |
| 487 | +// @Override |
| 488 | +// public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { |
| 489 | +// return sourceType.getType() == byte[].class && targetType.getType() == BinaryVector.class; |
| 490 | +// } |
| 491 | +// |
| 492 | +// @Nullable |
| 493 | +// @Override |
| 494 | +// public Set<ConvertiblePair> getConvertibleTypes() { |
| 495 | +// return Set.of(new ConvertiblePair(byte[].class, BinaryVector.class)); |
| 496 | +// } |
| 497 | +// |
| 498 | +// @Nullable |
| 499 | +// @Override |
| 500 | +// public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { |
| 501 | +// if(!matches(sourceType, targetType)) { |
| 502 | +// return source; |
| 503 | +// } |
| 504 | +// return convert((byte[]) source); |
| 505 | +// } |
| 506 | +// } |
| 507 | + |
476 | 508 | /**
|
477 | 509 | * {@link ConverterFactory} implementation converting {@link AtomicLong} into {@link Long}.
|
478 | 510 | *
|
|
0 commit comments