src/Model.js
function (model, pojo, options) {
  pojo = pojo || {};

  let props = model.serializeProperties || model.properties;

  props = props.filter(prop => (!model.propertyOptions[prop] || model.propertyOptions[prop].serialize !== false));

  props.forEach(key => {
    let obj;

    let o = model.propertyOptions[key];

    if (o && o.preSerialize) {
      obj = o.preSerialize(options);
    } else {
      obj = model[key];
    }

    if (obj instanceof Array) {
      let newArr = [];

      obj.forEach(item => {
        newArr.push(item instanceof Model ? item.serialize() : item);
      });

      pojo[key] = newArr;
    } else if (obj instanceof Model) {
      pojo[key] = obj.serialize(options);
    } else {
      pojo[key] = obj;
    }

    if (o && o.postSerialize) {
      o.postSerialize(options);
    }
  });

  if (model.postSerialize) {
    model.postSerialize(pojo, options);
  }

  return pojo;
}
function (model, pojo, options) {
  pojo = pojo || {};

  let props = model.serializeProperties || model.properties;

  props = props.filter(prop => (!model.propertyOptions[prop] || model.propertyOptions[prop].serialize !== false));

  props.forEach(key => {
    let obj;

    let o = model.propertyOptions[key];

    if (o && o.preSerialize) {
      obj = o.preSerialize(options);
    } else {
      obj = model[key];
    }

    if (obj instanceof Array) {
      let newArr = [];

      obj.forEach(item => {
        newArr.push(item instanceof Model ? item.serialize() : item);
      });

      pojo[key] = newArr;
    } else if (obj instanceof Model) {
      pojo[key] = obj.serialize(options);
    } else {
      pojo[key] = obj;
    }

    if (o && o.postSerialize) {
      o.postSerialize(options);
    }
  });

  if (model.postSerialize) {
    model.postSerialize(pojo, options);
  }

  return pojo;
}
function ( model , pojo , options ) { pojo = pojo || { } ; let props = model . serializeProperties || model . properties ; props = props . filter ( prop => ( ! model . propertyOptions [ prop ] || model . propertyOptions [ prop ] . serialize !== false ) ) ; props . forEach ( key => { let obj ; let o = model . propertyOptions [ key ] ; if ( o && o . preSerialize ) { obj = o . preSerialize ( options ) ; } else { obj = model [ key ] ; } if ( obj instanceof Array ) { let newArr = [ ] ; obj . forEach ( item => { newArr . push ( item instanceof Model ? item . serialize ( ) : item ) ; } ) ; pojo [ key ] = newArr ; } else if ( obj instanceof Model ) { pojo [ key ] = obj . serialize ( options ) ; } else { pojo [ key ] = obj ; } if ( o && o . postSerialize ) { o . postSerialize ( options ) ; } } ) ; if ( model . postSerialize ) { model . postSerialize ( pojo , options ) ; } return pojo ; }
Serialize a Ringa Model object to a POJO by iterating over properties recursively on any
descendent Model instances.

@param model
@param pojo
@returns {*|{}}
@private
Serialize a Ringa Model object to a POJO by iterating over properties recursively on any descendent Model instances .