Comparing version 0.4.23 to 0.4.24
@@ -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<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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
173114
5142
0
3