bravius commented on issue #236:
URL: https://github.com/apache/age/issues/236#issuecomment-1165005781
@jasperblues
_I meant at what point(s) in the pipleline from
(driver)-[:EXECUTES_STATEMENTS)->(apachAge) are we dependent on
parsing/serialization, and thus need to plug in custom replacer and reviver ?_
Pretty much any case that depends upon communicating JSON data over the
wire, such as between client and server.
I've solved the serialization issue using these custom replacer/reviver
functions for JSON.parse and JSON.stringify.
```
const NULL = 'n';
const BIGINT = 'i';
const STRING = 's';
const BOOLEAN = 'b';
const NUMBER = 'f';
/**
* BigInt compatible JSON.stringify replacer function
*/
export function json_replacer(key, value) {
const type = typeof value;
if (type === "string") {
return `${STRING}:${value}`;
} else if (type === "number") {
return `${NUMBER}:${value}`;
} else if (type === "bigint") {
return `${BIGINT}:${value}`;
} else if (type === "boolean") {
return `${BOOLEAN}:${value}`;
} else if (value === null) {
return `${NULL}:${value}`;
} else if (type === "object") {
return value;
} else {
throw new TypeError();
}
}
/**
* BitInt compatible JSON.parse reviver function
*/
export function json_reviver(key, value) {
const type = typeof value;
if (type === "string") {
const t = String(value).substring(0, 1);
const v = String(value).substring(2);
if (t === STRING) {
return String(v);
} else if (t === NUMBER) {
return Number(v);
} else if (t === BIGINT) {
return BigInt(v);
} else if (t === BOOLEAN) {
return Boolean(v);
} else if (t === NULL) {
return null;
} else {
throw new TypeError();
}
} else if (type === "object") {
return value;
} else {
throw new TypeError();
}
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]