Skip to content

Commit

Permalink
GH-2611: Remove MimeTypeJsonDeserializer
Browse files Browse the repository at this point in the history
Fixes: #2611

The `MimeTypeJsonDeserializer` was introduced a long time ago for backwards compatibility with old, unsupported, versions.
  • Loading branch information
Wzy19930507 committed Mar 4, 2024
1 parent 3e3d92d commit 265e55f
Showing 1 changed file with 1 addition and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 the original author or authors.
* Copyright 2017-2024 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.
Expand Down Expand Up @@ -34,17 +34,10 @@
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdNodeBasedDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.TextNode;
import com.fasterxml.jackson.databind.type.TypeFactory;

/**
* Default header mapper for Apache Kafka.
Expand Down Expand Up @@ -163,8 +156,6 @@ private DefaultKafkaHeaderMapper(boolean outbound, ObjectMapper objectMapper, St
Assert.notNull(objectMapper, "'objectMapper' must not be null");
Assert.noNullElements(patterns, "'patterns' must not have null elements");
this.objectMapper = objectMapper;
this.objectMapper
.registerModule(new SimpleModule().addDeserializer(MimeType.class, new MimeTypeJsonDeserializer()));
}

/**
Expand Down Expand Up @@ -426,39 +417,6 @@ protected boolean trusted(String requestedType) {
return true;
}


/**
* The {@link StdNodeBasedDeserializer} extension for {@link MimeType} deserialization.
* It is presented here for backward compatibility when older producers send {@link MimeType}
* headers as serialization version.
*/
private class MimeTypeJsonDeserializer extends StdNodeBasedDeserializer<MimeType> {

private static final long serialVersionUID = 1L;

MimeTypeJsonDeserializer() {
super(MimeType.class);
}

@Override
public MimeType convert(JsonNode root, DeserializationContext ctxt) throws IOException {
if (root instanceof TextNode) {
return MimeType.valueOf(root.asText());
}
else {
JsonNode type = root.get("type");
JsonNode subType = root.get("subtype");
JsonNode parameters = root.get("parameters");
Map<String, String> params =
DefaultKafkaHeaderMapper.this.objectMapper.readValue(parameters.traverse(),
TypeFactory.defaultInstance()
.constructMapType(HashMap.class, String.class, String.class));
return new MimeType(type.asText(), subType.asText(), params);
}
}

}

/**
* Represents a header that could not be decoded due to an untrusted type.
*/
Expand Down

0 comments on commit 265e55f

Please sign in to comment.