@microsoft/kiota-serialization-json
Version:
Implementation of Kiota Serialization interfaces for JSON
38 lines • 1.58 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { JsonParseNode } from "./jsonParseNode.js";
export class JsonParseNodeFactory {
/**
* Creates an instance of JsonParseNode.
* @param backingStoreFactory - The factory to create backing stores.
*/
constructor(backingStoreFactory) {
this.backingStoreFactory = backingStoreFactory;
}
getValidContentType() {
return "application/json";
}
getRootParseNode(contentType, content) {
if (!content) {
throw new Error("content cannot be undefined of empty");
}
else if (!contentType) {
throw new Error("content type cannot be undefined or empty");
}
else if (this.getValidContentType() !== contentType) {
throw new Error(`expected a ${this.getValidContentType()} content type`);
}
return new JsonParseNode(this.convertArrayBufferToJson(content), this.backingStoreFactory);
}
convertArrayBufferToJson(content) {
const decoder = new TextDecoder();
const contentAsStr = decoder.decode(content);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(contentAsStr);
}
}
//# sourceMappingURL=jsonParseNodeFactory.js.map