spring集成jsonignore属性

spring集成jsonignore属性,spring,spring-integration,Spring,Spring Integration,我试图忽略从JMS接收到的一些json信息: {"publishedDate":"2018","title":"How to","author":"rcade"} 我正在使用@JsonIgnoreProperties @JsonIgnoreProperties({"title", "author", "publishedDat

我试图忽略从JMS接收到的一些json信息:

{"publishedDate":"2018","title":"How to","author":"rcade"}
我正在使用
@JsonIgnoreProperties

@JsonIgnoreProperties({"title", "author", "publishedDate"})
public class Posts {
    @com.fasterxml.jackson.annotation.JsonIgnoreProperties({"publishedDate"})
    private String title;
    private String author;
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}

public class JsonToPojoTransformerBean {

    public Posts transform(@org.jetbrains.annotations.NotNull Message message) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        Posts result = mapper.readValue(message.getPayload().toString(), Posts.class);
        return result;
    }
}

然后我试着插入它们

 <int:transformer id="jsonToProdObjectTransformer" ref="JsonToPojoTransformerBean" input-channel="JmsInbound"
                     method="transform" output-channel="feed"/>

<int-jdbc:outbound-channel-adapter id="jdbcOutbound"
                                       channel="feed"
                                       data-source="dataSource"
                                       query="INSERT INTO posts(title, author)
                                       values(:payload[title], :payload[author])"/>

这是我第一次尝试它,为什么它不能作为
有效负载[标题]
?我需要如何为
查询
提供这些值?对于忽略一些json负载,我这样做是否正确?

完全不清楚
@JsonIgnoreProperties
主题与错误的SpEL表达式异常的关系,但我留给您来决定

因此,到目前为止,我们得到的是:

  • 表达式部分中的Spring集成将
    消息作为求值上下文根对象处理。
    消息
    的合同如下:

    public interface Message<T> {
    
     /**
      * Return the message payload.
      */
     T getPayload();
    
     /**
      * Return message headers for the message (never {@code null} but may be empty).
      */
     MessageHeaders getHeaders();
    
    }
    
    公共接口消息{
    /**
    *返回消息有效负载。
    */
    T getPayload();
    /**
    *返回消息的消息头(从不{@code null},但可能为空)。
    */
    MessageHeaders getHeaders();
    }
    
  • 因此,我们可以在表达式中执行
    headers
    payload
    ,作为对根对象的那些getter的引用

  • 您的中的有效负载是
    Posts
    对象。它实际上不是一个列表或数组,甚至不是对其执行
    []
    (索引)操作符的映射

  • 要访问那些
    标题
    作者
    ,您只需要遵循SpEL中的getter规则。因此,属性名为:
    值(:payload.title,:payload.author)的同一个普通点运算符

  • 如果这不起作用,您需要考虑将带有参数名别名的
    表达式EvaluationSqlParameterSourceFactory
    注入到该

    请参阅示例项目中的一些想法:


    另外,文档也会给出一些解释:

    再次感谢您。是的,我在那里搞砸了
    @JsonIgnoreProperties
    ,但现在一切都按照我的预期进行了。
    public interface Message<T> {
    
     /**
      * Return the message payload.
      */
     T getPayload();
    
     /**
      * Return message headers for the message (never {@code null} but may be empty).
      */
     MessageHeaders getHeaders();
    
    }