Skip to content

Commit 690f09a

Browse files
undo some of the previous changes
1 parent 57935fb commit 690f09a

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MongoConverters.java

+7-25
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.mongodb.core.convert;
1717

18-
import static org.springframework.data.convert.ConverterBuilder.*;
18+
import static org.springframework.data.convert.ConverterBuilder.reading;
1919

2020
import java.math.BigDecimal;
2121
import java.math.BigInteger;
@@ -47,14 +47,11 @@
4747
import org.bson.types.Code;
4848
import org.bson.types.Decimal128;
4949
import org.bson.types.ObjectId;
50-
5150
import org.springframework.core.convert.ConversionFailedException;
5251
import org.springframework.core.convert.TypeDescriptor;
5352
import org.springframework.core.convert.converter.ConditionalConverter;
5453
import org.springframework.core.convert.converter.Converter;
5554
import org.springframework.core.convert.converter.ConverterFactory;
56-
import org.springframework.core.env.Environment;
57-
import org.springframework.core.env.StandardEnvironment;
5855
import org.springframework.data.convert.ReadingConverter;
5956
import org.springframework.data.convert.WritingConverter;
6057
import org.springframework.data.domain.Vector;
@@ -174,20 +171,12 @@ public ObjectId convert(BigInteger source) {
174171
}
175172
}
176173

177-
enum BigDecimalToStringConverter implements Converter<BigDecimal, String>, ConditionalConverter {
174+
enum BigDecimalToStringConverter implements Converter<BigDecimal, String> {
178175
INSTANCE;
179176

180-
Environment env = new StandardEnvironment();
181-
182177
public String convert(BigDecimal source) {
183178
return source.toString();
184179
}
185-
186-
@Override
187-
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
188-
boolean flagPresent = env.containsProperty("mongo.decimal128.representation");
189-
return !flagPresent || env.getProperty("mongo.decimal128.representation", String.class, "string").equals("string");
190-
}
191180
}
192181

193182
/**
@@ -220,23 +209,16 @@ public BigDecimal convert(Decimal128 source) {
220209
}
221210
}
222211

223-
enum BigIntegerToStringConverter implements Converter<BigInteger, String>, ConditionalConverter {
212+
@WritingConverter
213+
enum BigIntegerToStringConverter implements Converter<BigInteger, String> {
224214
INSTANCE;
225215

226-
Environment env = new StandardEnvironment();
227-
228216
public String convert(BigInteger source) {
229217
return source.toString();
230218
}
231-
232-
@Override
233-
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
234-
235-
boolean flagPresent = env.containsProperty("mongo.decimal128.representation");
236-
return !flagPresent || env.getProperty("mongo.decimal128.representation", String.class, "string").equals("string");
237-
}
238219
}
239220

221+
@ReadingConverter
240222
enum StringToBigIntegerConverter implements Converter<String, BigInteger> {
241223
INSTANCE;
242224

@@ -431,13 +413,13 @@ public NumberToNumberConverter(Class<T> targetType) {
431413
@Override
432414
public T convert(Number source) {
433415

434-
if(targetType == Decimal128.class) {
416+
if (targetType == Decimal128.class) {
435417

436418
if (source instanceof BigDecimal bigDecimal) {
437419
return targetType.cast(BigDecimalToDecimal128Converter.INSTANCE.convert(bigDecimal));
438420
}
439421

440-
if(source instanceof BigInteger bigInteger) {
422+
if (source instanceof BigInteger bigInteger) {
441423
return targetType.cast(new Decimal128(bigInteger.longValueExact()));
442424
}
443425
}

0 commit comments

Comments
 (0)