Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protobuf MessageConverter #24087

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-messaging/spring-messaging.gradle
Expand Up @@ -15,6 +15,7 @@ dependencies {
optional("javax.xml.bind:jaxb-api")
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
optional("com.google.protobuf:protobuf-java-util")
testCompile("javax.inject:javax.inject-tck")
testCompile("javax.servlet:javax.servlet-api")
testCompile("javax.validation:validation-api")
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -47,7 +48,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter

protected final Log logger = LogFactory.getLog(getClass());

private final List<MimeType> supportedMimeTypes;
private List<MimeType> supportedMimeTypes;

@Nullable
private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
Expand All @@ -62,17 +63,24 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
* @param supportedMimeType the supported MIME type
*/
protected AbstractMessageConverter(MimeType supportedMimeType) {
Assert.notNull(supportedMimeType, "supportedMimeType is required");
this.supportedMimeTypes = Collections.<MimeType>singletonList(supportedMimeType);
setSupportedMimeTypes(Collections.singletonList(supportedMimeType));
}

/**
* Construct an {@code AbstractMessageConverter} supporting multiple MIME types.
* @param supportedMimeTypes the supported MIME types
*/
protected AbstractMessageConverter(Collection<MimeType> supportedMimeTypes) {
Assert.notNull(supportedMimeTypes, "supportedMimeTypes must not be null");
this.supportedMimeTypes = new ArrayList<>(supportedMimeTypes);
setSupportedMimeTypes(new ArrayList<>(supportedMimeTypes));
}

/**
* Construct an {@code AbstractMessageConverter} supporting multiple MIME types.
* @param supportedMimeTypes the supported MIME types
* @since 5.2.2
*/
protected AbstractMessageConverter(MimeType... supportedMimeTypes) {
setSupportedMimeTypes(Arrays.asList(supportedMimeTypes));
}


Expand All @@ -83,6 +91,15 @@ public List<MimeType> getSupportedMimeTypes() {
return Collections.unmodifiableList(this.supportedMimeTypes);
}

/**
* Set the list of {@link MimeType} objects supported by this converter.
* @since 5.2.2
*/
protected void setSupportedMimeTypes(List<MimeType> supportedMimeTypes) {
Assert.notNull(supportedMimeTypes, "supportedMimeTypes must not be null");
this.supportedMimeTypes = supportedMimeTypes;
}

/**
* Configure the {@link ContentTypeResolver} to use to resolve the content
* type of an input message.
Expand Down
Expand Up @@ -84,7 +84,7 @@ public MappingJackson2MessageConverter() {
* @since 4.1.5
*/
public MappingJackson2MessageConverter(MimeType... supportedMimeTypes) {
super(Arrays.asList(supportedMimeTypes));
super(supportedMimeTypes);
this.objectMapper = initObjectMapper();
}

Expand Down
Expand Up @@ -70,7 +70,7 @@ public MarshallingMessageConverter() {
* @param supportedMimeTypes the MIME types
*/
public MarshallingMessageConverter(MimeType... supportedMimeTypes) {
super(Arrays.asList(supportedMimeTypes));
super(supportedMimeTypes);
}

/**
Expand Down