JacksonCborSerializer should use CBOR ofc, #28918
* When we updated to Jackson 2.10 (prior Akka 2.6.0) the new JsonFactoryBuilder was used. That doesn't preserve the formatParserFeatures and formatGeneratorFeatures from the base CBORFactory and therefore the format was plain JSON. * rolling update compatibility
This commit is contained in:
parent
6361bdb153
commit
ef9a2c79c6
4 changed files with 91 additions and 9 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package akka.serialization.jackson
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
|
|
@ -17,6 +18,7 @@ import java.util.logging.FileHandler
|
|||
import scala.collection.immutable
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.actor.ActorRef
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor.Address
|
||||
|
|
@ -569,6 +571,17 @@ class JacksonJsonSerializerSpec extends JacksonSerializerSpec("jackson-json") {
|
|||
""")(sys => checkSerialization(Elephant("Dumbo", 1), sys))
|
||||
}
|
||||
}
|
||||
|
||||
// issue #28918
|
||||
"cbor compatibility for reading json" in {
|
||||
val msg = SimpleCommand("abc")
|
||||
val jsonSerializer = serializerFor(msg)
|
||||
jsonSerializer.identifier should ===(31)
|
||||
val manifest = jsonSerializer.manifest(msg)
|
||||
val bytes = jsonSerializer.toBinary(msg)
|
||||
val deserialized = serialization().deserialize(bytes, 32, manifest).get
|
||||
deserialized should be(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -626,6 +639,20 @@ abstract class JacksonSerializerSpec(serializerName: String)
|
|||
val manifest = serializer.manifest(obj)
|
||||
val serializerId = serializer.identifier
|
||||
val blob = serializeToBinary(obj)
|
||||
|
||||
// Issue #28918, check that CBOR format is used (not JSON).
|
||||
if (blob.length > 0) {
|
||||
serializer match {
|
||||
case _: JacksonJsonSerializer =>
|
||||
if (!JacksonSerializer.isGZipped(blob))
|
||||
new String(blob.take(1), StandardCharsets.UTF_8) should ===("{")
|
||||
case _: JacksonCborSerializer =>
|
||||
new String(blob.take(1), StandardCharsets.UTF_8) should !==("{")
|
||||
case _ =>
|
||||
throw new IllegalArgumentException(s"Unexpected serializer $serializer")
|
||||
}
|
||||
}
|
||||
|
||||
val deserialized = deserializeFromBinary(blob, serializerId, manifest, sys)
|
||||
deserialized should ===(obj)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue