const cleanObject = require('clean-object');
const JSONAPISerializer = require('json-api-serializer');
const Serializer = new JSONAPISerializer();

function deepMap(obj, iterator) {
  return _.transform(obj, function(result, val, key) {
    result[key] = _.isObject(val) ?
      deepMap(val, iterator) :
      iterator.call(this, val, key, obj);
  });
}

function _setIdTypeToString(object) {

  if (typeof object['id'] === "number") {
    object['id'] = object['id'].toString();
  }

  return object;
}

module.exports = {

  serialize: function(modelName, data) {

    Serializer.register(modelName, {
      convertCase: 'kebab-case',
      id: 'id'
    });

    // JSON API specifies resource IDs MUST be strings
    // Let's convert all Sails integer index to strings
    if (typeof data === "object") {
      data = _setIdTypeToString(data);
    } else if (typeof data === "array") {
      data.forEach(function(object) {
        object = _setIdTypeToString(object);
      });
    }

    var returnedValue = cleanObject(Serializer.serialize(modelName, data));
    delete returnedValue.jsonapi; // Let's ignore the version for now

    return returnedValue;
  }
}

@@ -654,16 +654,49 @@
    %7D);%0A%0A
+    var dataToSerialize = null;%0A%0A
     // J
@@ -810,72 +810,198 @@
 if (
-typeof data === %22object%22) %7B%0A      data = _setIdTypeToString(data
+data instanceof Array) %7B%0A      dataToSerialize = %5B%5D;%0A%0A      data.forEach(function(resource) %7B%0A        var object = _setIdTypeToString(resource);%0A        dataToSerialize.push(object);%0A      %7D
 );%0A 
@@ -1035,13 +1035,14 @@
 == %22
-array
+object
 %22) %7B
@@ -1056,50 +1056,19 @@
 data
-.forEach(function(object) %7B%0A        object
+ToSerialize
  = _
@@ -1085,32 +1085,20 @@
 oString(
-object);%0A      %7D
+data
 );%0A    %7D
@@ -1171,16 +1171,27 @@
 me, data
+ToSerialize
 ));%0A    

Fix bug id in array were not updated in JsonApiService serializer