|
|
|
@ -51,7 +51,6 @@ import org.junit.jupiter.params.provider.ValueSource; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.beans.ConversionNotSupportedException; |
|
|
|
import org.springframework.beans.ConversionNotSupportedException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -108,6 +107,7 @@ import org.springframework.data.util.TypeInformation; |
|
|
|
import org.springframework.lang.NonNull; |
|
|
|
import org.springframework.lang.NonNull; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.BasicDBList; |
|
|
|
import com.mongodb.BasicDBList; |
|
|
|
import com.mongodb.BasicDBObject; |
|
|
|
import com.mongodb.BasicDBObject; |
|
|
|
@ -3410,11 +3410,38 @@ class MappingMongoConverterUnitTests { |
|
|
|
assertThat(document).containsEntry("map.foo", "2.5"); |
|
|
|
assertThat(document).containsEntry("map.foo", "2.5"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-5036
|
|
|
|
|
|
|
|
void withCustomBigIntegerConversion() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MappingMongoConverter converter = createConverter(MongoCustomConversions.BigDecimalRepresentation.STRING, |
|
|
|
|
|
|
|
new CustomBigIntegerToStringConverter()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WithBigNumericValues container = new WithBigNumericValues(); |
|
|
|
|
|
|
|
container.bigInteger = BigInteger.TEN; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document document = new org.bson.Document(); |
|
|
|
|
|
|
|
converter.write(container, document); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(document).containsEntry("bigInteger", "BigInteger('10')"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private MappingMongoConverter createConverter( |
|
|
|
private MappingMongoConverter createConverter( |
|
|
|
MongoCustomConversions.BigDecimalRepresentation bigDecimalRepresentation) { |
|
|
|
MongoCustomConversions.BigDecimalRepresentation bigDecimalRepresentation) { |
|
|
|
|
|
|
|
|
|
|
|
MongoCustomConversions conversions = MongoCustomConversions.create( |
|
|
|
return createConverter(bigDecimalRepresentation, new ByteBufferToDoubleHolderConverter()); |
|
|
|
it -> it.registerConverter(new ByteBufferToDoubleHolderConverter()).bigDecimal(bigDecimalRepresentation)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MappingMongoConverter createConverter( |
|
|
|
|
|
|
|
MongoCustomConversions.BigDecimalRepresentation bigDecimalRepresentation, Converter<?, ?>... customConverters) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MongoCustomConversions conversions = MongoCustomConversions.create(it -> { |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(customConverters)) { |
|
|
|
|
|
|
|
for (Converter<?, ?> customConverter : customConverters) { |
|
|
|
|
|
|
|
it.registerConverter(customConverter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it.bigDecimal(bigDecimalRepresentation); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
MongoMappingContext mappingContext = new MongoMappingContext(); |
|
|
|
MongoMappingContext mappingContext = new MongoMappingContext(); |
|
|
|
mappingContext.setApplicationContext(context); |
|
|
|
mappingContext.setApplicationContext(context); |
|
|
|
@ -3437,6 +3464,14 @@ class MappingMongoConverterUnitTests { |
|
|
|
return target; |
|
|
|
return target; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@WritingConverter |
|
|
|
|
|
|
|
static class CustomBigIntegerToStringConverter implements Converter<BigInteger, String> { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String convert(BigInteger source) { |
|
|
|
|
|
|
|
return "BigInteger('%s')".formatted(source.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class WithVector { |
|
|
|
static class WithVector { |
|
|
|
|
|
|
|
|
|
|
|
Vector embeddings; |
|
|
|
Vector embeddings; |
|
|
|
@ -4084,8 +4119,7 @@ class MappingMongoConverterUnitTests { |
|
|
|
@Field(targetType = FieldType.DECIMAL128) //
|
|
|
|
@Field(targetType = FieldType.DECIMAL128) //
|
|
|
|
BigDecimal bigDecimal; |
|
|
|
BigDecimal bigDecimal; |
|
|
|
|
|
|
|
|
|
|
|
@Field(targetType = FieldType.DECIMAL128) |
|
|
|
@Field(targetType = FieldType.DECIMAL128) BigInteger bigInteger; |
|
|
|
BigInteger bigInteger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Field(targetType = FieldType.INT64) //
|
|
|
|
@Field(targetType = FieldType.INT64) //
|
|
|
|
Date dateAsLong; |
|
|
|
Date dateAsLong; |
|
|
|
@ -4100,6 +4134,10 @@ class MappingMongoConverterUnitTests { |
|
|
|
Date dateAsObjectId; |
|
|
|
Date dateAsObjectId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class WithBigNumericValues { |
|
|
|
|
|
|
|
BigInteger bigInteger; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class WrapperAroundWithUnwrapped { |
|
|
|
static class WrapperAroundWithUnwrapped { |
|
|
|
|
|
|
|
|
|
|
|
String someValue; |
|
|
|
String someValue; |
|
|
|
|