Deprecate ExtensionRegistryInitializer in protobuf support

In order to be consistent with SPR-15776, and since it does not
provide clear added value, this commit deprecates
ExtensionRegistryInitializer and uses ExtensionRegistry
parameter instead in ProtobufHttpMessageConverter and
ProtobufJsonFormatHttpMessageConverter constructors.

Issue: SPR-17081
This commit is contained in:
Sebastien Deleuze
2018-07-24 17:18:53 +02:00
parent dd4468a74a
commit 36bbbab02d
5 changed files with 80 additions and 15 deletions

View File

@@ -25,10 +25,13 @@ import com.google.protobuf.ExtensionRegistry;
* <p>This interface provides a facility to populate the {@code ExtensionRegistry}.
*
* @author Alex Antonov
* @author Sebastien Deleuze
* @since 4.1
* @see <a href="https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/ExtensionRegistry">
* com.google.protobuf.ExtensionRegistry</a>
* @deprecated as of Spring Framework 5.1, use {@link ExtensionRegistry} based contructors instead
*/
@Deprecated
public interface ExtensionRegistryInitializer {
/**

View File

@@ -77,6 +77,7 @@ import static org.springframework.http.MediaType.TEXT_PLAIN;
* @author Alex Antonov
* @author Brian Clozel
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @since 4.1
* @see FormatFactory
* @see JsonFormat
@@ -107,7 +108,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
private static final Map<Class<?>, Method> methodCache = new ConcurrentReferenceHashMap<>();
private final ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
final ExtensionRegistry extensionRegistry;
@Nullable
private final ProtobufFormatSupport protobufFormatSupport;
@@ -117,20 +118,34 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
* Construct a new {@code ProtobufHttpMessageConverter}.
*/
public ProtobufHttpMessageConverter() {
this(null);
this(null, null);
}
/**
* Construct a new {@code ProtobufHttpMessageConverter} with an
* initializer that allows the registration of message extensions.
* @param registryInitializer an initializer for message extensions
* @deprecated as of Spring Framework 5.1, use {@link #ProtobufHttpMessageConverter(ExtensionRegistry)} instead
*/
@Deprecated
public ProtobufHttpMessageConverter(@Nullable ExtensionRegistryInitializer registryInitializer) {
this(null, registryInitializer);
this(null, null);
if (registryInitializer != null) {
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
}
}
/**
* Construct a new {@code ProtobufHttpMessageConverter} with a registry that specifies
* protocol message extensions.
* @param extensionRegistry the registry to populate
*/
public ProtobufHttpMessageConverter(ExtensionRegistry extensionRegistry) {
this(null, extensionRegistry);
}
ProtobufHttpMessageConverter(@Nullable ProtobufFormatSupport formatSupport,
@Nullable ExtensionRegistryInitializer registryInitializer) {
@Nullable ExtensionRegistry extensionRegistry) {
if (formatSupport != null) {
this.protobufFormatSupport = formatSupport;
@@ -148,9 +163,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
setSupportedMediaTypes(Arrays.asList(this.protobufFormatSupport != null ?
this.protobufFormatSupport.supportedMediaTypes() : new MediaType[] {PROTOBUF, TEXT_PLAIN}));
if (registryInitializer != null) {
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
}
this.extensionRegistry = (extensionRegistry == null ? ExtensionRegistry.newInstance() : extensionRegistry);
}

View File

@@ -16,6 +16,7 @@
package org.springframework.http.converter.protobuf;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.util.JsonFormat;
import org.springframework.lang.Nullable;
@@ -32,6 +33,7 @@ import org.springframework.lang.Nullable;
* with 3.3 or higher recommended.
*
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @since 5.0
* @see JsonFormat#parser()
* @see JsonFormat#printer()
@@ -44,7 +46,7 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
* {@link JsonFormat.Parser} and {@link JsonFormat.Printer} configuration.
*/
public ProtobufJsonFormatHttpMessageConverter() {
this(null, null, null);
this(null, null, (ExtensionRegistry)null);
}
/**
@@ -56,7 +58,22 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
public ProtobufJsonFormatHttpMessageConverter(
@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
this(parser, printer, null);
this(parser, printer, (ExtensionRegistry)null);
}
/**
* Construct a new {@code ProtobufJsonFormatHttpMessageConverter} with the given
* {@link JsonFormat.Parser} and {@link JsonFormat.Printer} configuration, also
* accepting a registry that specifies protocol message extensions.
* @param parser the JSON parser configuration
* @param printer the JSON printer configuration
* @param extensionRegistry the registry to populate
* @since 5.1
*/
public ProtobufJsonFormatHttpMessageConverter(@Nullable JsonFormat.Parser parser,
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) {
super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry);
}
/**
@@ -66,11 +83,17 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
* @param parser the JSON parser configuration
* @param printer the JSON printer configuration
* @param registryInitializer an initializer for message extensions
* @deprecated as of Spring Framework 5.1, use
* {@link #ProtobufJsonFormatHttpMessageConverter(JsonFormat.Parser, JsonFormat.Printer, ExtensionRegistry)} instead
*/
@Deprecated
public ProtobufJsonFormatHttpMessageConverter(@Nullable JsonFormat.Parser parser,
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistryInitializer registryInitializer) {
super(new ProtobufJavaUtilSupport(parser, printer), registryInitializer);
super(new ProtobufJavaUtilSupport(parser, printer), null);
if (registryInitializer != null) {
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
}
}
}