Deprecate Base64Utils in favor of Java's Base64
Originally, `Base64Utils` was providing base64 encoding and decoding utilities, bridging to commons-codecs or Java 8, if available. Since then, only the Java 8 variant remains and Spring Framework 6 requires now Java 17. This utility class doesn't provide additional checks or syntactic sugar over what's in Java already. As a result, this commit deprecates this class in favor of `Base64` and schedules the removal of this class completely. Closes gh-28434
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.http.converter.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Base64;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
@@ -26,7 +27,6 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
/**
|
||||
* A simple utility class for obtaining a Google Gson 2.x {@link GsonBuilder}
|
||||
@@ -36,7 +36,6 @@ import org.springframework.util.Base64Utils;
|
||||
* @author Roy Clarkson
|
||||
* @since 4.1
|
||||
* @see GsonFactoryBean#setBase64EncodeByteArrays
|
||||
* @see org.springframework.util.Base64Utils
|
||||
*/
|
||||
public abstract class GsonBuilderUtils {
|
||||
|
||||
@@ -59,12 +58,12 @@ public abstract class GsonBuilderUtils {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(Base64Utils.encodeToString(src));
|
||||
return new JsonPrimitive(Base64.getEncoder().encodeToString(src));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] deserialize(JsonElement json, Type type, JsonDeserializationContext cxt) {
|
||||
return Base64Utils.decodeFromString(json.getAsString());
|
||||
return Base64.getDecoder().decode(json.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user