CBOR Deserialization: Option[Long] Field Causes ClassCastException in Pekko Shard Entity Messaging
When sending messages to shard entities in a Pekko cluster, we encountered a subtle issue with Jackson CBOR serialization. A case class containing an Option[Long] field was deserialized incorrectly: if the numeric value was small enough, it was represented as a java.lang.Integer rather than a java.lang.Long. This led to a ClassCastException during unboxing (via BoxesRunTime.unboxToLong) on the receiving shard. Annotating the Option[Long] field with @JsonDeserialize(contentAs = classOf[java.lang.Long]) fixed the issue by forcing Jackson to treat the value as a Long. This report aims to help others avoid the same pitfall in distributed Pekko setups.
https://github.com/scala/bug/issues/12327
关闭于 2025-03-25 5 条评论