Skip to content

Commit

Permalink
* Remove generic arg from the ContentTypeDelegatingDataMarshaller
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Apr 10, 2020
1 parent 2f8c5e7 commit 310abc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,34 @@
*
* @since 5.3
*/
public class ContentTypeDelegatingDataMarshaller<T> implements DataMarshaller<byte[], T, String> {
public class ContentTypeDelegatingDataMarshaller implements DataMarshaller<byte[], Object, String> {

private final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();

private final List<Encoder<?>> encoders = new ArrayList<>();

@SafeVarargs
public ContentTypeDelegatingDataMarshaller(Encoder<T>... encoders) {
public ContentTypeDelegatingDataMarshaller(Encoder<?>... encoders) {
this.encoders.add(CharSequenceEncoder.allMimeTypes());
setEncoders(encoders);
}

@SafeVarargs
public final void setEncoders(Encoder<T>... encoders) {
public final void setEncoders(Encoder<?>... encoders) {
Assert.notNull(encoders, "'encoders' must not be null");
Assert.noNullElements(encoders, "'encoders' must not contain null elements");
this.encoders.addAll(Arrays.asList(encoders));
}

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public byte[] marshal(T data, Map<String, String> headers) throws RuntimeException {
public byte[] marshal(Object data, Map<String, String> headers) throws RuntimeException {
String contentType = headers.get(MessageHeaders.CONTENT_TYPE);
if (contentType == null) { // Assume JSON by default
return Json.binaryMarshal(data, headers);
}
else {
ResolvableType elementType = ResolvableType.forClass(data.getClass());
MimeType mimeType = MimeType.valueOf(contentType);
Encoder<T> encoder = encoder(elementType, mimeType);
Encoder<Object> encoder = encoder(elementType, mimeType);
DataBuffer dataBuffer =
encoder.encodeValue(data, this.dataBufferFactory, elementType,
mimeType, (Map<String, Object>) (Map) headers);
Expand All @@ -86,10 +84,10 @@ public byte[] marshal(T data, Map<String, String> headers) throws RuntimeExcepti
}

@SuppressWarnings("unchecked")
private Encoder<T> encoder(ResolvableType elementType, MimeType mimeType) {
private Encoder<Object> encoder(ResolvableType elementType, MimeType mimeType) {
for (Encoder<?> encoder : this.encoders) {
if (encoder.canEncode(elementType, mimeType)) {
return (Encoder<T>) encoder;
return (Encoder<Object>) encoder;
}
}
throw new IllegalArgumentException("No encoder for " + elementType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public enum Result {

private final URI source;

private final ContentTypeDelegatingDataMarshaller<Object> dataMarshaller =
new ContentTypeDelegatingDataMarshaller<>();
private final ContentTypeDelegatingDataMarshaller dataMarshaller = new ContentTypeDelegatingDataMarshaller();

@Nullable
private final EventStep<AttributesImpl, Object, byte[], String> wireBuilder;
Expand Down Expand Up @@ -136,8 +135,7 @@ public void setExtensionExpression(@Nullable Expression extensionExpression) {
* Plus {@link MessageHeaders#CONTENT_TYPE} must be present in the request message.
* @param encoders the {@link Encoder}s to use.
*/
@SafeVarargs
public final void setEncoders(Encoder<Object>... encoders) {
public final void setEncoders(Encoder<?>... encoders) {
this.dataMarshaller.setEncoders(encoders);
}

Expand Down

0 comments on commit 310abc4

Please sign in to comment.