Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-GH-5037-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-GH-5037-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>5.0.0-GH-5037-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.HashSet;
import java.util.Set;

import org.bson.UuidRepresentation;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
Expand Down Expand Up @@ -226,7 +225,6 @@ protected boolean autoIndexCreation() {
protected MongoClientSettings mongoClientSettings() {

MongoClientSettings.Builder builder = MongoClientSettings.builder();
builder.uuidRepresentation(UuidRepresentation.STANDARD);
configureClientSettings(builder);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.bson.UuidRepresentation;
import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
Expand Down Expand Up @@ -162,7 +162,6 @@ protected MongoClientSettings computeClientSetting() {
getOrDefault(port, "" + ServerAddress.defaultPort())));

Builder builder = MongoClientSettings.builder().applyConnectionString(connectionString);
builder.uuidRepresentation(UuidRepresentation.STANDARD);

if (mongoClientSettings != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ private void writeSimpleInternal(@Nullable Object value, Bson bson, MongoPersist

if (typeHint != null && Object.class != typeHint) {

// TODO this is weird and leads to double-conversion in some cases, e.g. BigDecimal -> Decimal128 -> BigDecimal
if (conversionService.canConvert(value.getClass(), typeHint)) {
value = doConvert(value, typeHint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Currency;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -83,19 +88,65 @@ abstract class MongoConverters {
private MongoConverters() {}

/**
* Returns the converters to be registered.
* Returns the {@code Date} to UTC converters to be registered.
*
* @return
* @since 1.9
* @since 5.0
*/
static Collection<Object> getConvertersToRegister() {
static Collection<Object> getDateToUtcConverters() {

List<Object> converters = new ArrayList<>();
List<Object> converters = new ArrayList<>(3);

converters.add(DateToUtcLocalDateConverter.INSTANCE);
converters.add(DateToUtcLocalTimeConverter.INSTANCE);
converters.add(DateToUtcLocalDateTimeConverter.INSTANCE);

return converters;
}

/**
* Returns the {@code Decimal128} converters to be registered.
*
* @return
* @since 5.0
*/
static Collection<Converter<?, ?>> getBigNumberDecimal128Converters() {

List<Converter<?, ?>> converters = new ArrayList<>(3);

converters.add(BigDecimalToDecimal128Converter.INSTANCE);
converters.add(Decimal128ToBigDecimalConverter.INSTANCE);
converters.add(BigIntegerToDecimal128Converter.INSTANCE);

return converters;
}

/**
* Returns the {@code String} converters to be registered for {@link BigInteger} and {@link BigDecimal}.
*
* @return
* @since 5.0
*/
static Collection<Converter<?, ?>> getBigNumberStringConverters() {

List<Converter<?, ?>> converters = new ArrayList<>(2);

converters.add(BigDecimalToStringConverter.INSTANCE);
converters.add(BigIntegerToStringConverter.INSTANCE);

return converters;
}

/**
* Returns the converters to be registered.
*
* @return
* @since 1.9
*/
static Collection<Object> getConvertersToRegister() {

List<Object> converters = new ArrayList<>();

converters.add(URLToStringConverter.INSTANCE);
converters.add(StringToURLConverter.INSTANCE);
converters.add(DocumentToStringConverter.INSTANCE);
Expand All @@ -116,6 +167,9 @@ static Collection<Object> getConvertersToRegister() {
converters.add(ListToVectorConverter.INSTANCE);
converters.add(BinaryVectorToMongoVectorConverter.INSTANCE);

converters.add(StringToBigDecimalConverter.INSTANCE);
converters.add(StringToBigIntegerConverter.INSTANCE);

converters.add(reading(BsonUndefined.class, Object.class, it -> null));
converters.add(reading(String.class, URI.class, URI::create).andWriting(URI::toString));

Expand Down Expand Up @@ -174,6 +228,7 @@ public ObjectId convert(BigInteger source) {
}
}

@WritingConverter
enum BigDecimalToStringConverter implements Converter<BigDecimal, String> {
INSTANCE;

Expand All @@ -185,6 +240,7 @@ public String convert(BigDecimal source) {
/**
* @since 2.2
*/
@WritingConverter
enum BigDecimalToDecimal128Converter implements Converter<BigDecimal, Decimal128> {
INSTANCE;

Expand All @@ -196,6 +252,7 @@ public Decimal128 convert(BigDecimal source) {
/**
* @since 5.0
*/
@WritingConverter
enum BigIntegerToDecimal128Converter implements Converter<BigInteger, Decimal128> {
INSTANCE;

Expand All @@ -204,6 +261,7 @@ public Decimal128 convert(BigInteger source) {
}
}

@ReadingConverter
enum StringToBigDecimalConverter implements Converter<String, BigDecimal> {
INSTANCE;

Expand All @@ -215,6 +273,7 @@ enum StringToBigDecimalConverter implements Converter<String, BigDecimal> {
/**
* @since 2.2
*/
@ReadingConverter
enum Decimal128ToBigDecimalConverter implements Converter<Decimal128, BigDecimal> {
INSTANCE;

Expand Down Expand Up @@ -630,4 +689,35 @@ public Instant convert(BsonTimestamp source) {
return Instant.ofEpochSecond(source.getTime(), 0);
}
}

@ReadingConverter
private enum DateToUtcLocalDateTimeConverter implements Converter<Date, LocalDateTime> {

INSTANCE;

@Override
public LocalDateTime convert(Date source) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(source.getTime()), ZoneId.of("UTC"));
}
}

@ReadingConverter
private enum DateToUtcLocalTimeConverter implements Converter<Date, LocalTime> {
INSTANCE;

@Override
public LocalTime convert(Date source) {
return DateToUtcLocalDateTimeConverter.INSTANCE.convert(source).toLocalTime();
}
}

@ReadingConverter
private enum DateToUtcLocalDateConverter implements Converter<Date, LocalDate> {
INSTANCE;

@Override
public LocalDate convert(Date source) {
return DateToUtcLocalDateTimeConverter.INSTANCE.convert(source).toLocalDate();
}
}
}
Loading