Skip to content

Commit d8721c9

Browse files
mp911deodrotbohm
authored andcommitted
DATAMONGO-2156 - Remove dependency to javax.xml.bind.
We now no longer use DatatypeConverter to convert byte[] to its Base64-representation but use Spring Framework's Base64 utils. Original pull request: #626.
1 parent 8fe734d commit d8721c9

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ExpressionEvaluatingParameterBinder.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.util.regex.Matcher;
3434
import java.util.regex.Pattern;
3535

36-
import javax.xml.bind.DatatypeConverter;
37-
3836
import org.bson.codecs.BinaryCodec;
3937
import org.bson.codecs.Codec;
4038
import org.bson.codecs.UuidCodec;
@@ -48,6 +46,7 @@
4846
import org.springframework.expression.spel.standard.SpelExpressionParser;
4947
import org.springframework.lang.Nullable;
5048
import org.springframework.util.Assert;
49+
import org.springframework.util.Base64Utils;
5150
import org.springframework.util.CollectionUtils;
5251
import org.springframework.util.StringUtils;
5352

@@ -579,7 +578,7 @@ static class BinaryValue extends EncodableValue {
579578
public String encode(CodecRegistryProvider provider, boolean quoted) {
580579

581580
if (quoted) {
582-
return DatatypeConverter.printBase64Binary(this.value);
581+
return Base64Utils.encodeToString(this.value);
583582
}
584583

585584
return encode(provider, new Binary(this.value), BinaryCodec::new);

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveStringBasedMongoQueryUnitTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.util.Collections;
2828
import java.util.Map;
2929

30-
import javax.xml.bind.DatatypeConverter;
31-
3230
import org.bson.BSON;
3331
import org.bson.Document;
3432
import org.junit.Before;
@@ -53,6 +51,7 @@
5351
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
5452
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
5553
import org.springframework.expression.spel.standard.SpelExpressionParser;
54+
import org.springframework.util.Base64Utils;
5655

5756
/**
5857
* Unit tests for {@link ReactiveStringBasedMongoQuery}.
@@ -219,7 +218,7 @@ public void shouldSupportNonQuotedBinaryDataReplacement() throws Exception {
219218

220219
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
221220
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
222-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
221+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
223222

224223
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
225224
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.Map;
3030
import java.util.UUID;
3131

32-
import javax.xml.bind.DatatypeConverter;
33-
3432
import org.bson.BSON;
3533
import org.bson.Document;
3634
import org.junit.Before;
@@ -56,6 +54,7 @@
5654
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
5755
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
5856
import org.springframework.expression.spel.standard.SpelExpressionParser;
57+
import org.springframework.util.Base64Utils;
5958

6059
/**
6160
* Unit tests for {@link StringBasedMongoQuery}.
@@ -318,7 +317,7 @@ public void shouldSupportNonQuotedBinaryDataReplacement() {
318317

319318
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
320319
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
321-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
320+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
322321

323322
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
324323
}
@@ -333,7 +332,7 @@ public void shouldSupportNonQuotedBinaryCollectionDataReplacement() {
333332

334333
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
335334
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { $in: [{'$binary' : '"
336-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
335+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
337336

338337
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
339338
}

0 commit comments

Comments
 (0)