Skip to content

Commit de80b9a

Browse files
authored
Merge pull request #1665 from zZHorizonZz/patch
fix: prevent error on undefined byte array value in serialization writers
2 parents 1b6bfc9 + cf96887 commit de80b9a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/serialization/json/src/jsonSerializationWriter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { DateOnly, Duration, type Guid, isUntypedNode, type ModelSerializerFunct
1111
export class JsonSerializationWriter implements SerializationWriter {
1212
public writeByteArrayValue(key?: string, value?: ArrayBuffer | null): void {
1313
if (!value) {
14-
throw new Error("value cannot be undefined");
14+
return;
1515
}
16+
1617
const b64 = inNodeEnv() ? Buffer.from(value).toString("base64") : btoa(new TextDecoder().decode(value));
1718
this.writeStringValue(key, b64);
1819
}

packages/serialization/text/src/textSerializationWriter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { inNodeEnv, type DateOnly, type Duration, type Guid, type ModelSerialize
1111
export class TextSerializationWriter implements SerializationWriter {
1212
public writeByteArrayValue(key?: string, value?: ArrayBuffer | null): void {
1313
if (!value) {
14-
throw new Error("value cannot be undefined");
14+
return;
1515
}
16-
const b64 = inNodeEnv() ? Buffer.from(value).toString("base64") : btoa(new TextDecoder().decode(value));
1716

17+
const b64 = inNodeEnv() ? Buffer.from(value).toString("base64") : btoa(new TextDecoder().decode(value));
1818
this.writeStringValue(key, b64);
1919
}
2020
private static readonly noStructuredDataMessage = "text does not support structured data";

0 commit comments

Comments
 (0)