@@ -617,9 +617,6 @@ private fun ObjectData.writeMsgpack(packer: MessagePacker) {
617617 if (objectId != null ) fieldCount++
618618 value?.let {
619619 fieldCount++
620- if (it.value is JsonElement ) {
621- fieldCount + = 1 // For extra "encoding" field
622- }
623620 }
624621
625622 packer.packMapHeader(fieldCount)
@@ -649,10 +646,8 @@ private fun ObjectData.writeMsgpack(packer: MessagePacker) {
649646 packer.writePayload(v.data)
650647 }
651648 is JsonObject , is JsonArray -> {
652- packer.packString(" string" )
653- packer.packString(v.toString())
654- packer.packString(" encoding" )
655649 packer.packString(" json" )
650+ packer.packString(v.toString())
656651 }
657652 }
658653 }
@@ -665,8 +660,6 @@ private fun readObjectData(unpacker: MessageUnpacker): ObjectData {
665660 val fieldCount = unpacker.unpackMapHeader()
666661 var objectId: String? = null
667662 var value: ObjectValue ? = null
668- var encoding: String? = null
669- var stringValue: String? = null
670663
671664 for (i in 0 until fieldCount) {
672665 val fieldName = unpacker.unpackString().intern()
@@ -680,33 +673,29 @@ private fun readObjectData(unpacker: MessageUnpacker): ObjectData {
680673 when (fieldName) {
681674 " objectId" -> objectId = unpacker.unpackString()
682675 " boolean" -> value = ObjectValue (unpacker.unpackBoolean())
683- " string" -> stringValue = unpacker.unpackString()
676+ " string" -> value = ObjectValue ( unpacker.unpackString() )
684677 " number" -> value = ObjectValue (unpacker.unpackDouble())
685678 " bytes" -> {
686679 val size = unpacker.unpackBinaryHeader()
687680 val bytes = ByteArray (size)
688681 unpacker.readPayload(bytes)
689682 value = ObjectValue (Binary (bytes))
690683 }
691- " encoding" -> encoding = unpacker.unpackString()
684+ " json" -> {
685+ val jsonString = unpacker.unpackString()
686+ val parsed = JsonParser .parseString(jsonString)
687+ value = ObjectValue (
688+ when {
689+ parsed.isJsonObject -> parsed.asJsonObject
690+ parsed.isJsonArray -> parsed.asJsonArray
691+ else ->
692+ throw ablyException(" Invalid JSON string for json field" , ErrorCode .MapValueDataTypeUnsupported , HttpStatusCode .InternalServerError )
693+ }
694+ )
695+ }
692696 else -> unpacker.skipValue()
693697 }
694698 }
695699
696- // Handle string with encoding if needed
697- if (stringValue != null && encoding == " json" ) {
698- val parsed = JsonParser .parseString(stringValue)
699- value = ObjectValue (
700- when {
701- parsed.isJsonObject -> parsed.asJsonObject
702- parsed.isJsonArray -> parsed.asJsonArray
703- else ->
704- throw ablyException(" Invalid JSON string for encoding=json" , ErrorCode .MapValueDataTypeUnsupported , HttpStatusCode .InternalServerError )
705- }
706- )
707- } else if (stringValue != null ) {
708- value = ObjectValue (stringValue)
709- }
710-
711700 return ObjectData (objectId = objectId, value = value)
712701}
0 commit comments