diff --git a/lib/list.js b/lib/list.js index 61e384b6..038e4323 100644 --- a/lib/list.js +++ b/lib/list.js @@ -64,7 +64,12 @@ function List(items, itemType, parent) { } List.prototype.toItem = function(item) { - return isClass(this.itemType) ? new this.itemType(item) : this.itemType(item); + if (isClass(this.itemType)) { + return new this.itemType(item); + } else { + if (Array.isArray(item)) return item; + else return this.itemType(item); + } }; items.forEach(function(item, i) { @@ -91,7 +96,10 @@ List.prototype.push = function(obj) { List.prototype.toObject = function(onlySchema, removeHidden, removeProtected) { const items = []; this.forEach(function(item) { - if (item && typeof item === 'object' && item.toObject) { + if (item && Array.isArray(item) && item.toArray) { + const subArray = item.toArray(); + items.push(subArray); + } else if (item && typeof item === 'object' && item.toObject) { items.push(item.toObject(onlySchema, removeHidden, removeProtected)); } else { items.push(item); diff --git a/test/introspection.test.js b/test/introspection.test.js index 2d672f27..a70bcaef 100644 --- a/test/introspection.test.js +++ b/test/introspection.test.js @@ -27,6 +27,9 @@ const json = { {label: 'work', id: 'x@sample.com'}, {label: 'home', id: 'x@home.com'}, ], + nestedArray: [ + [{msg: 'Hi'}], + ], tags: [], };