I have a simple class 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);
}
}
When I push a message to ActiveMQ via jmsTemplate.convertAndSend(destination, new B("foo", "bar"))
, the actual message in queue is the following:
{
"incomeField": "foo",
"anotherIncomeField": "bar",
"fixedValueField": null
}
I handle JMS messages with @JmsListener(destination = "my-destination)
and receive an object of type B
with fixedValueField
set to null
, while I expect it to be someFixedValue
as I set it in private
constructor.
When I debug all this stuff, I see that @JsonCreator
is called correctly and my object has expected values for all fields, but when Jackson finishes deserialization, I see that fixedValueField
is null
. Why this can happen?
Note that all the fields are final
Environment:
This is the answer why this works in such way - stackoverflow.com/a/30341178/4760059
This is possible a fix - stackoverflow.com/a/42142268/4760059
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.