I have the following thrift file:
union D{ 1: string s; }
struct B{ 1: required D d; }
struct C{ 1: required D d; }
union A{ 1: B b; 2: C c; }
service Test { void store(1: A a) }
And I have the following JSON object, which was obtained by parsing a string.
var data_json = {
'b': {
'd': {
's': "hello"
}
}
};
I'm trying to write a thrift client in Nodejs which calls the store
method with data_json
as its argument, but I get the following error when I do so:
/home/aakash/Documents/thrift0/gen-nodejs/test_types.js:225
this.b.write(output);
^
TypeError: Object #<Object> has no method 'write'
at Object.A.write (/home/aakash/Documents/thrift0/gen-nodejs/test_types.js:225:12)
at Object.Test_store_args.write (/home/aakash/Documents/thrift0/gen-nodejs/Test.js:57:12)
at Object.TestClient.send_store (/home/aakash/Documents/thrift0/gen-nodejs/Test.js:113:8)
at Object.TestClient.store (/home/aakash/Documents/thrift0/gen-nodejs/Test.js:105:8)
at Object.<anonymous> (/home/aakash/Documents/thrift0/client.js:40:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
However, it works fine when I pass the following object as argument:
var data_thrift = new ttypes.A({
'b': new ttypes.B({
'd': new ttypes.D({
's': "hello"
})
})
});
Is there a way to pass data_json
directly to store
, or a way to convert data_json
to data_thrift
?