diff --git a/apps/macos/Sources/ClawdisProtocol/GatewayModels.swift b/apps/macos/Sources/ClawdisProtocol/GatewayModels.swift index 6b7c4a475..faafc1ea2 100644 --- a/apps/macos/Sources/ClawdisProtocol/GatewayModels.swift +++ b/apps/macos/Sources/ClawdisProtocol/GatewayModels.swift @@ -585,7 +585,9 @@ public enum GatewayFrame: Codable { private static func decodePayload(_ type: T.Type, from raw: [String: AnyCodable]) throws -> T { - let data = try JSONSerialization.data(withJSONObject: raw) + // raw is [String: AnyCodable] which is not directly JSONSerialization-compatible. + // Round-trip through JSONEncoder so AnyCodable can encode itself safely. + let data = try JSONEncoder().encode(raw) let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } diff --git a/scripts/protocol-gen-swift.ts b/scripts/protocol-gen-swift.ts index d5c18342c..3145b4ea7 100644 --- a/scripts/protocol-gen-swift.ts +++ b/scripts/protocol-gen-swift.ts @@ -198,7 +198,9 @@ function emitGatewayFrame(): string { const helper = ` private static func decodePayload(_ type: T.Type, from raw: [String: AnyCodable]) throws -> T { - let data = try JSONSerialization.data(withJSONObject: raw) + // raw is [String: AnyCodable] which is not directly JSONSerialization-compatible. + // Round-trip through JSONEncoder so AnyCodable can encode itself safely. + let data = try JSONEncoder().encode(raw) let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) }