Comparing version 0.4.26 to 0.4.27
@@ -338,3 +338,8 @@ /* | ||
// this is what a stripNulls null looks like. | ||
obj[child.tag] = null; | ||
if (!field.coerceTo) { | ||
obj[child.tag] = null; | ||
} | ||
else { | ||
obj[child.tag] = field.coerce(child.text); | ||
} | ||
} else if (field) { | ||
@@ -341,0 +346,0 @@ obj[child.tag] = field.coerce(child.text); |
@@ -61,2 +61,4 @@ /** | ||
return value.toString().toLowerCase() !== 'false' && value.toString().toLowerCase() !== 'False'; | ||
} else if (coerceTo === 'array' && (value === null || value === '')) { | ||
return []; | ||
} else { | ||
@@ -68,3 +70,3 @@ return value; | ||
/** | ||
/** | ||
* allows you to coerce a value to a native value. this is handy when your numbers and booleans get converted to | ||
@@ -71,0 +73,0 @@ * strings outside of your control. |
@@ -14,3 +14,3 @@ { | ||
"description": "Serilization and Validation Framework for objects in RESTful APIs", | ||
"version": "0.4.26", | ||
"version": "0.4.27", | ||
"homepage": "https://github.com/racker/node-swiz", | ||
@@ -17,0 +17,0 @@ "repository": { |
@@ -46,3 +46,3 @@ /* | ||
F('ipaddress' , {'src' : 'get_public_address'}), | ||
F('public_ips', {'singular': 'ip', 'filterFrom': ['public']}), | ||
F('public_ips', {'singular': 'ip', 'filterFrom': ['public'], 'coerceTo': 'array'}), | ||
F('state', {'enumerated' : {inactive: 0, active: 1, full_no_new_checks: 2}, | ||
@@ -78,9 +78,9 @@ 'filterFrom': ['public', 'test1']}), | ||
}), | ||
O('accounting', | ||
{ | ||
'fields': [ | ||
F('monitoring_zones', { 'val': new Chain().isInt() }), | ||
F('notification_plans', { 'val': new Chain().isInt() }), | ||
F('notification_types', { 'val': new Chain().isInt() }), | ||
F('monitoring_zones', { 'val': new Chain().isInt() }), | ||
F('notification_plans', { 'val': new Chain().isInt() }), | ||
F('notification_types', { 'val': new Chain().isInt() }), | ||
F('entities', { 'val': new Chain().isInt() }) | ||
@@ -187,3 +187,6 @@ // you get the ideal. | ||
}; | ||
var node1 = new Node(); | ||
node1.public_ips = []; | ||
async.waterfall([ | ||
@@ -220,3 +223,3 @@ function nullRemainsJS(callback) { | ||
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_XML, 1, objWithNull, function(err, res) { | ||
assert.ifError(err); | ||
assert.ifError(err); | ||
var reconstituted = sw.deserializeXml(res); | ||
@@ -226,4 +229,14 @@ assert.ok(reconstituted['option2'] === undefined); | ||
}); | ||
} | ||
}, | ||
function emptyArrayWithCoerceToArray(callback) { | ||
var sw = new swiz.Swiz(def, { stripNulls: false}); | ||
sw.serialize(swiz.SERIALIZATION.SERIALIZATION_XML, 1, node1, function(err, res) { | ||
assert.ifError(err); | ||
var reconstituted = sw.deserializeXml(res); | ||
assert.deepEqual(reconstituted.public_ips, []); | ||
callback(err); | ||
}); | ||
}, | ||
], function(err) { | ||
@@ -233,3 +246,3 @@ assert.ifError(err); | ||
}); | ||
} | ||
@@ -293,3 +306,3 @@ | ||
exports['test_can_roundtrip_raw_object'] = function(test, assert) { | ||
// this is a pure javascript object that doesn't have a getSerializerType function, but is decorated with | ||
// this is a pure javascript object that doesn't have a getSerializerType function, but is decorated with | ||
// serializerType fields to support serialization to xml. | ||
@@ -296,0 +309,0 @@ var sw = new swiz.Swiz(def, {stripNulls: false}); |
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
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
175302
5200