Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swiz

Package Overview
Dependencies
Maintainers
4
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swiz - npm Package Compare versions

Comparing version 0.4.23 to 0.4.24

53

lib/serializer.js

@@ -387,20 +387,45 @@ /*

Swiz.prototype._deserializeXml = function(elem) {
var self = this;
var def = self._defFor(elem.tag);
if (!def) {
var self = this, children, obj,
def = self._defFor(elem.tag);
if (elem.tag !== 'container' && !def) {
throw new Error('No definition for this type; unable to deserialize ' + elem.tag);
}
var obj;
if (def.plural === elem.tag) {
// we'll be emitting a list.
obj = [];
// iterate over children, emitting objects that conform to def.
elem._children.forEach(function(child) {
// todo: assert elem has no attributes.
obj.push(self._emitFromDef(child, def));
if (elem.tag === 'container') {
obj = {
values: [],
metadata: {}
};
// iterate over values.
elem._children[0]._children.forEach(function(e) {
obj.values.push(self._deserializeXml(e));
});
} else {
// we'll be emitting an object that conforms to def.
obj = self._emitFromDef(elem, def);
obj.metadata = {};
children = elem.findall('metadata/*');
children.forEach(function(e) {
var name, value;
name = e.tag;
value = e.text || null;
obj.metadata[name] = value;
});
}
else {
if (def.plural === elem.tag) {
// we'll be emitting a list.
obj = [];
// iterate over children, emitting objects that conform to def.
elem._children.forEach(function(child) {
// todo: assert elem has no attributes.
obj.push(self._emitFromDef(child, def));
});
} else {
// we'll be emitting an object that conforms to def.
obj = self._emitFromDef(elem, def);
}
}
return obj;

@@ -407,0 +432,0 @@ }

@@ -14,3 +14,3 @@ {

"description": "Serilization and Validation Framework for objects in RESTful APIs",
"version": "0.4.23",
"version": "0.4.24",
"homepage": "https://github.com/racker/node-swiz",

@@ -17,0 +17,0 @@ "repository": {

@@ -267,2 +267,21 @@ /*

exports['test_deserializeXml_container_object'] = function(test, assert) {
var xml = '<container><values><node id="15245" name="gggggg"><is_active>false</is_active><agent_name>gl&lt;ah</' +
'agent_name><ipaddress>123.33.22.1</ipaddress>' +
'<public_ips><ip>123.45.55.44</ip><ip>122.123.32.2</ip></public_ips>' +
'<state>active</state>' +
'<opts><nodeOpts>' +
'<option1>defaultval</option1>' +
'<option2>defaultval</option2>' +
'<option3>something</option3>' +
'</nodeOpts></opts>' +
'<data><foo>thingone</foo><bar>thingtwo</bar></data></node>' +
'</values><metadata><page>1</page><next_key>blah</next_key>' +
'</metadata></container>';
var sw = new swiz.Swiz(def, {stripNulls: true});
var obj = sw.deserializeXml(xml);
assert.deepEqual(obj.metadata, {'page': 1, 'next_key': 'blah'});
test.finish();
};
exports['test_can_roundtrip_raw_object'] = function(test, assert) {

@@ -269,0 +288,0 @@ // this is a pure javascript object that doesn't have a getSerializerType function, but is decorated with

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc