Java HttpRequestHandlingMessagingGateway JSON数组负载
我无法使用HTTP入站适配器将JSON数组转换为Java HttpRequestHandlingMessagingGateway JSON数组负载,java,json,spring,jackson,spring-integration,Java,Json,Spring,Jackson,Spring Integration,我无法使用HTTP入站适配器将JSON数组转换为SendgridTxEvent类型的对象列表,它总是以ArrayList而不是list结束。配置: public HttpRequestHandlingMessagingGateway sendgridMessageAdapter(@Qualifier("sendgridWebhookEvents") MessageChannel channel) { HttpRequestHandlingMessagingGateway http
SendgridTxEvent
类型的对象列表,它总是以ArrayList
而不是list
结束。配置:
public HttpRequestHandlingMessagingGateway sendgridMessageAdapter(@Qualifier("sendgridWebhookEvents") MessageChannel channel) {
HttpRequestHandlingMessagingGateway httpInboundChannelAdapter = new HttpRequestHandlingMessagingGateway(false);
RequestMapping mapping = new RequestMapping();
mapping.setMethods(HttpMethod.POST);
mapping.setPathPatterns("/webhook/sendgrid");
ParameterizedTypeReference<List<SendgridTxEvent>> ptr = new ParameterizedTypeReference<List<SendgridTxEvent>>() {
};
httpInboundChannelAdapter.setRequestMapping(mapping);
httpInboundChannelAdapter.setRequestChannel(channel);
httpInboundChannelAdapter.setRequestPayloadType(ResolvableType.forType(ptr));
return httpInboundChannelAdapter;
}
我在框架中提出了一个问题来解决这个问题:
同时,作为一种解决方法,我建议在
HttpRequestHandlingMessagingGateway
中预期有效负载为String
或byte[]
,然后使用POJO@Transformer
下游,通过ObjectMapper
直接转换,并且已经预期的请发布其他文件。从json到对象文件的映射?@AlexLemesios添加了SendgridTxEvent
。是的,从JSON到对象集合是否有SendgridTxEvent的包装器?像是一个集合的类吗?@AlexLemesios否。我认为我明确地将目标类型指定为ParameterizedTypeReference(){}
。我想知道适配器为什么会忽略它。似乎org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport#extractRequestBody
没有保留调用ResolvableType#resolve
的实际类型参数,因此http入站适配器不可能将JSON数组转换为所需类型。
@JsonIgnoreProperties(ignoreUnknown = true)
public class SendgridTxEvent {
public enum Event {
PROCESSED,
DROPPED,
DELIVERED,
BOUNCE,
DEFERRED,
OPEN,
CLICK,
UNSUBSCRIBE,
SPAMREPORT;
@JsonCreator
public static Event forValue(String value) {
return Event.valueOf(value.toUpperCase());
}
}
private String email;
private Long timestamp;
private Event event;
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
private List<String> category;
private String sgEventId;
private String sgMessageId;
//getters, setters
}