Monday 13 March 2017

Functions are not serialized using "serialijse" module of nodejs

Normal JSON is working fine for me like {id:1,"name"="test"} is serialised properly but on define function in JSON object is not being serialized properly.

Below is the code

  var s = require("serialijse")
  var o = {"b":function (){alert('hello world');}}
  var str = s.serialize(o);
  console.log(str);

Error shown

/Users/acid/node_js/node_modules/serialijse/lib/serialijse.js:116
                    throw new Error("invalid typeof " + typeof object + " " + JSON.stringify(object, null, " "));
                    ^

Error: invalid typeof function undefined
    at _serialize (/Users/acid/node_js/node_modules/serialijse/lib/serialijse.js:116:27)
    at _serialize_object (/Users/acid/node_js/node_modules/serialijse/lib/serialijse.js:89:38)
    at _serialize (/Users/acid/node_js/node_modules/serialijse/lib/serialijse.js:113:21)
    at Object.serialize (/Users/acid/node_js/node_modules/serialijse/lib/serialijse.js:122:19)
    at Object.<anonymous> (/Users/acid/node_js/newtest/serial.js:4:15)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

What can be the possible way to rectify this ?



via Ashu

No comments:

Post a Comment