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.
This commit is contained in:
Mark Paluch
2018-12-04 16:01:05 +01:00
committed by Oliver Drotbohm
parent 3effd9ae6f
commit 0698f8bcb8
3 changed files with 7 additions and 10 deletions

View File

@@ -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;
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 {
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);

View File

@@ -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;
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 {
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()));
}

View File

@@ -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;
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 {
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 {
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()));
}