Hello,
we were using commercetools java sdk 17.26.0.
We had a handler for the messages where we would send in asn parameter com.commercetools.api.models.message.Message
So it would look like
public void processMessage(final ServiceBusReceivedMessageContext context)
{
final BinaryData data = context.getMessage().getBody();
final Message message = data.toObject(Message.class);
handler.handle(message);
}
In handler we would, if needed just cast to the class we new this handler should handle
final DiscountedPrice discount = ((StandalonePriceDiscountSetMessage) message).getDiscounted();
With updating to 19.3.0, this is not working anymore because com.commercetools.api.models.message.Message does not have @JsonSubTypes annotation and it just deserializes to com.commercetools.api.models.message.MessageImpl.
Only solution I found is to do it with jackson like this
JsonUtils.getConfiguredObjectMapper().readValue(context.getMessage().getBody().toString(), StandalonePriceDiscountSetMessage.class)
Same thing happened to Change messages where @JsonSubTypes were removed from com.commercetools.api.models.subscription.DeliveryPayload.
Now even this does not work, throws an exception, and was working before:
final DeliveryPayload payload = context.getMessage().getBody().toObject(DeliveryPayload.class);
Here also I have to do it like this now:
final DeliveryPayload deliveryPayload = JsonUtils.getConfiguredObjectMapper().readValue(data.toString(), DeliveryPayload.class);
My question is, is there any smarter way to deserialize to the specific implementation class now in 19.3.0? Am I missing some method or some helper class or whatever?
Because it is strange that something that was working OOTB and pretty much Generic, was now removed.
Thanks and best regards,
Tomislav Hlevnjak