Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jackson在调用@JsonCreator后进行额外初始化_Java_Spring Boot_Jackson_Jms_Deserialization - Fatal编程技术网

Java Jackson在调用@JsonCreator后进行额外初始化

Java Jackson在调用@JsonCreator后进行额外初始化,java,spring-boot,jackson,jms,deserialization,Java,Spring Boot,Jackson,Jms,Deserialization,我有一个简单的类a: @Getter @RequiredArgsConstructor(access = AccessLevel.PACKAGE) class A { private final String incomeField; private final String anotherIncomeField; private final String fixedValueField; } class B extends A { private B(final Str

我有一个简单的类
a

@Getter
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
class A {

  private final String incomeField;
  private final String anotherIncomeField;
  private final String fixedValueField;

}

class B extends A {

  private B(final String incomeField, final String anotherIncomeField) {
    super(incomeField, anotherIncomeField, "someFixedValue");
  }

  @JsonCreator
  public static B of(@JsonProperty("incomeField") final String incomeField, @JsonProperty("anotherIncomeField") final String anotherIncomeField) {
      return new B(incomeField, anotherIncomeField);
  }
}
当我通过
jmsTemplate.convertAndSend(目的地,新B(“foo”,“bar”))
将消息推送到ActiveMQ时,队列中的实际消息如下所示:

{
   "incomeField": "foo",
   "anotherIncomeField": "bar",
   "fixedValueField": null
}
我使用
@JmsListener(destination=“my destination”)
处理JMS消息,并接收类型为
B
的对象,其中
fixedValueField
设置为
null
,而我希望它是
someFixedValue
,就像我在
private
构造函数中设置的那样

当我调试所有这些东西时,我看到
@JsonCreator
被正确调用,并且我的对象具有所有字段的预期值,但当Jackson完成反序列化时,我看到
fixedValueField
null
。 为什么会发生这种情况

请注意,所有字段都是
final

环境:

  • 爪哇11
  • 弹簧护套2.1.3.1释放
  • 杰克逊2.9.8
  • ActiveMQ 5.15.8

这就是为什么会这样的答案-stackoverflow.com/a/30341178/4760059


这是一个可能的修复-stackoverflow.com/a/42142268/4760059这就是为什么它会以这种方式工作的答案-stackoverflow.com/a/30341178/4760059

这可能是一个修复-stackoverflow.com/a/42142268/4760059