Skip to content

Commit

Permalink
#24022 - added protobuf MessageConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
parviz-93 committed Nov 28, 2019
1 parent 6ed1b58 commit 7a16cff
Show file tree
Hide file tree
Showing 18 changed files with 1,719 additions and 22 deletions.
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

0 comments on commit 7a16cff

Please sign in to comment.