Browse Source

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.
pull/627/head
Mark Paluch 7 years ago committed by Oliver Drotbohm
parent
commit
d8721c9930
  1. 5
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ExpressionEvaluatingParameterBinder.java
  2. 5
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveStringBasedMongoQueryUnitTests.java
  3. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java

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

@ -33,8 +33,6 @@ import java.util.function.Supplier; @@ -33,8 +33,6 @@ import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.bind.DatatypeConverter;
import org.bson.codecs.BinaryCodec;
import org.bson.codecs.Codec;
import org.bson.codecs.UuidCodec;
@ -48,6 +46,7 @@ import org.springframework.expression.Expression; @@ -48,6 +46,7 @@ import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@ -579,7 +578,7 @@ class ExpressionEvaluatingParameterBinder { @@ -579,7 +578,7 @@ class ExpressionEvaluatingParameterBinder {
public String encode(CodecRegistryProvider provider, boolean quoted) {
if (quoted) {
return DatatypeConverter.printBase64Binary(this.value);
return Base64Utils.encodeToString(this.value);
}
return encode(provider, new Binary(this.value), BinaryCodec::new);

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

@ -27,8 +27,6 @@ import java.lang.reflect.Method; @@ -27,8 +27,6 @@ import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Map;
import javax.xml.bind.DatatypeConverter;
import org.bson.BSON;
import org.bson.Document;
import org.junit.Before;
@ -53,6 +51,7 @@ import org.springframework.data.repository.Repository; @@ -53,6 +51,7 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.Base64Utils;
/**
* Unit tests for {@link ReactiveStringBasedMongoQuery}.
@ -219,7 +218,7 @@ public class ReactiveStringBasedMongoQueryUnitTests { @@ -219,7 +218,7 @@ public class ReactiveStringBasedMongoQueryUnitTests {
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
}

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

@ -29,8 +29,6 @@ import java.util.List; @@ -29,8 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.xml.bind.DatatypeConverter;
import org.bson.BSON;
import org.bson.Document;
import org.junit.Before;
@ -56,6 +54,7 @@ import org.springframework.data.repository.Repository; @@ -56,6 +54,7 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.Base64Utils;
/**
* Unit tests for {@link StringBasedMongoQuery}.
@ -318,7 +317,7 @@ public class StringBasedMongoQueryUnitTests { @@ -318,7 +317,7 @@ public class StringBasedMongoQueryUnitTests {
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
}
@ -333,7 +332,7 @@ public class StringBasedMongoQueryUnitTests { @@ -333,7 +332,7 @@ public class StringBasedMongoQueryUnitTests {
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { $in: [{'$binary' : '"
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
}

Loading…
Cancel
Save