/*
 * Automatically generated by preplate
 */
goog.provide('{{namespace}}.{{name}}');

goog.require('goog.json');

goog.require('prestans.types.Model.EventType');
goog.require('prestans.types.Model.AttributeChangedEvent');

goog.require('prestans.types.Model');

{% for dependency in dependencies %}
goog.require('{{dependency}}');
{% endfor %}

/**
 * @constructor
 * @extends {prestans.types.Model}
*/
{{namespace}}.{{name}} = function(opt_json, opt_minified) {

    //Setup base model
    prestans.types.Model.call(this);

    if(goog.isDef(opt_minified) && goog.isBoolean(opt_minified) && opt_minified && goog.isDefAndNotNull(opt_json)) {
{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' %}
        this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}(opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], true);
{% elif attribute.blueprint_type == 'array' %}
{% if attribute.element_template_is_model %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: {{namespace}}.{{attribute.element_template}},
            opt_json: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]],
            opt_minified: opt_minified,
            opt_opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'string' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.String({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, opt_opt_maxLength: {{attribute.element_template.max_length}}, opt_minLength: {{attribute.element_template.min_length}}, format: {{attribute.element_template.format}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'integer' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Integer({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'float' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Float({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'boolean' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Boolean({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}}),
            opt_json: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% endif %}
{% elif attribute.blueprint_type == 'string' %}
        this.{{attribute.ccif}}_ = new prestans.types.String({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}, opt_maxLength: {{attribute.max_length}}, opt_minLength: {{attribute.min_length}}, format: {{attribute.format}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'boolean' %}
        this.{{attribute.ccif}}_ = new prestans.types.Boolean({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'integer' %}
        this.{{attribute.ccif}}_ = new prestans.types.Integer({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'float' %}
        this.{{attribute.ccif}}_ = new prestans.types.Float({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'datetime' %}
        this.{{attribute.ccif}}_ = new prestans.types.DateTime({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}, timezone: {{attribute.timezone}}, utc: {{attribute.utc}}});
{% elif attribute.blueprint_type == 'date' %}
        this.{{attribute.ccif}}_ = new prestans.types.Date({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'time' %}
        this.{{attribute.ccif}}_ = new prestans.types.Time({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'data_url_file' %}
        this.{{attribute.ccif}}_ = new prestans.types.DataURLFile({value: opt_json[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]], required: {{attribute.required}}, allowed_mime_types: {{attribute.allowed_mime_types}}});
{% endif %}
{% endfor %}
    }
    else if(goog.isDefAndNotNull(opt_json)) {
{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' %}
        this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}(opt_json["{{attribute.name}}"]);
{% elif attribute.blueprint_type == 'array' %}
{% if attribute.element_template_is_model %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({elementTemplate: {{namespace}}.{{attribute.element_template}}, opt_json: opt_json["{{attribute.name}}"], opt_maxLength: {{attribute.max_length}}, opt_minLength: {{attribute.min_length}}});
{% elif attribute.element_template.blueprint_type == 'string' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.String({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, opt_maxLength: {{attribute.element_template.max_length}}, opt_minLength: {{attribute.element_template.min_length}}, format: {{attribute.element_template.format}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json["{{attribute.name}}"],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'integer' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Integer({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json["{{attribute.name}}"],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'float' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Float({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_json: opt_json["{{attribute.name}}"],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'boolean' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Boolean({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}}),
            opt_json: opt_json["{{attribute.name}}"],
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% endif %}
{% elif attribute.blueprint_type == 'string' %}
        this.{{attribute.ccif}}_ = new prestans.types.String({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}, opt_maxLength: {{attribute.max_length}}, opt_minLength: {{attribute.min_length}}, format: {{attribute.format}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'boolean' %}
        this.{{attribute.ccif}}_ = new prestans.types.Boolean({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'integer' %}
        this.{{attribute.ccif}}_ = new prestans.types.Integer({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'float' %}
        this.{{attribute.ccif}}_ = new prestans.types.Float({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == 'datetime' %}
        this.{{attribute.ccif}}_ = new prestans.types.DateTime({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}, timezone: {{attribute.timezone}}, utc: {{attribute.utc}}});
{% elif attribute.blueprint_type == 'date' %}
        this.{{attribute.ccif}}_ = new prestans.types.Date({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'time' %}
        this.{{attribute.ccif}}_ = new prestans.types.Time({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == 'data_url_file' %}
        this.{{attribute.ccif}}_ = new prestans.types.DataURLFile({value: opt_json["{{attribute.name}}"], required: {{attribute.required}}, allowed_mime_types: {{attribute.allowed_mime_types}}});
{% endif %}
{% endfor %}
    }
    else {
{% for attribute in attributes %}
{% if attribute.blueprint_type == 'model' %}
        this.{{attribute.ccif}}_ = new {{namespace}}.{{attribute.model_template}}();
{% elif attribute.blueprint_type == 'array' %}
{% if attribute.element_template_is_model %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({elementTemplate: {{namespace}}.{{attribute.element_template}}, opt_maxLength: {{attribute.max_length}}, opt_minLength: {{attribute.min_length}}});
{% elif attribute.element_template.blueprint_type == 'string' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.String({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, opt_maxLength: {{attribute.element_template.max_length}}, opt_minLength: {{attribute.element_template.min_length}}, format: {{attribute.element_template.format}}, choices: {{attribute.element_template.choices}}}),
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'integer' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Integer({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'float' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Float({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}, maximum: {{attribute.element_template.maximum}}, minimum: {{attribute.element_template.minimum}}, choices: {{attribute.element_template.choices}}}),
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% elif attribute.element_template.blueprint_type == 'boolean' %}
        this.{{attribute.ccif}}_ = new prestans.types.Array({
            elementTemplate: new prestans.types.Boolean({required: {{attribute.element_template.required}}, defaultValue: {{attribute.element_template.default}}}),
            opt_maxLength: {{attribute.max_length}},
            opt_minLength: {{attribute.min_length}}
        });
{% endif %}
{% elif attribute.blueprint_type == "string" %}
        this.{{attribute.ccif}}_ = new prestans.types.String({required: {{attribute.required}}, defaultValue: {{attribute.default}}, opt_maxLength: {{attribute.max_length}}, opt_minLength: {{attribute.min_length}}, format: {{attribute.format}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == "boolean" %}
        this.{{attribute.ccif}}_ = new prestans.types.Boolean({required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == "integer" %}
        this.{{attribute.ccif}}_ = new prestans.types.Integer({required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == "float" %}
        this.{{attribute.ccif}}_ = new prestans.types.Float({required: {{attribute.required}}, defaultValue: {{attribute.default}}, maximum: {{attribute.maximum}}, minimum: {{attribute.minimum}}, choices: {{attribute.choices}}});
{% elif attribute.blueprint_type == "datetime" %}
        this.{{attribute.ccif}}_ = new prestans.types.DateTime({required: {{attribute.required}}, defaultValue: {{attribute.default}}, timezone: {{attribute.timezone}}, utc: {{attribute.utc}}});
{% elif attribute.blueprint_type == "date" %}
        this.{{attribute.ccif}}_ = new prestans.types.Date({required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == "time" %}
        this.{{attribute.ccif}}_ = new prestans.types.Time({required: {{attribute.required}}, defaultValue: {{attribute.default}}});
{% elif attribute.blueprint_type == "data_url_file" %}
        this.{{attribute.ccif}}_ = new prestans.types.DataURLFile({required: {{attribute.required}}, allowed_mime_types: {{attribute.allowed_mime_types}}});
{% endif %}
{% endfor %}
    }

    //listen for array events
    {% for attribute in attributes %}{% if attribute.blueprint_type == "array" %}
this.{{attribute.ccif}}_.listen(prestans.types.Array.EventType.ARRAY_CHANGED, function(event) {
        this.dispatchEvent(new prestans.types.Model.AttributeChangedEvent({
            identifier: "{{attribute.ccif}}",
            previousValue: null,
            currentValue: null
        }));
    }, false, this);
    {% endif %}{% endfor %}

};
goog.inherits({{namespace}}.{{name}}, prestans.types.Model);



{% for attribute in attributes %}
{{namespace}}.{{name}}.prototype.{{attribute.ccif}}_ = null;
{% if attribute.format != "null" %}
{{namespace}}.{{name}}.{{attribute.cc}}StringFormat = new RegExp({{attribute.format}});
{% endif %}
{% if isinstance(attribute.choices, list) %}
{{namespace}}.{{name}}.{{attribute.cc}}Choices = {{attribute.choices}};
{% endif %}
{% endfor %}

//Rewrite map
{{namespace}}.{{name}}.REWRITE_MAP = {
{% for attribute in attributes %}
{% if loop.last %}
    "{{attribute.name}}": "{{attribute.map_name}}"
{% else %}
    "{{attribute.name}}": "{{attribute.map_name}}",
{% endif %}
{% endfor %}
};

//Reverse rewrite map
{{namespace}}.{{name}}.REVERSE_REWRITE_MAP = {
{% for attribute in attributes %}
{% if loop.last %}
    "{{attribute.map_name}}": "{{attribute.name}}"
{% else %}
    "{{attribute.map_name}}": "{{attribute.name}}",
{% endif %}
{% endfor %}
};

{% for attribute in attributes %}
{{namespace}}.{{name}}.prototype.get{{attribute.cc}} = function() {
{% if attribute.blueprint_type == 'model' or attribute.blueprint_type == 'array' %}
    return this.{{attribute.ccif}}_;
{% else %}
    return this.{{attribute.ccif}}_.getValue();
{% endif %}
};

{{namespace}}.{{name}}.prototype.set{{attribute.cc}} = function(value) {
{% if attribute.blueprint_type == 'array' %}
    var previousArray_ = this.{{attribute.ccif}}_;
{% if attribute.element_template_is_model %}
    if(value instanceof prestans.types.Array && value.getElementTemplate() == {{namespace}}.{{attribute.element_template}}) {
{% else %}
    if(value instanceof prestans.types.Array && value.getElementTemplate() instanceof prestans.types.{{attribute.element_template.client_class_name}}) {
{% endif %}
        this.{{attribute.ccif}}_ = value;
        this.dispatchAttributeChangedEvent_("{{attribute.ccif}}", previousArray_, this.{{attribute.ccif}}_);
        return true;
    }
    else
        return false;
{% elif attribute.blueprint_type == 'model' %}
    var previousModel_ = this.{{attribute.ccif}}_;
    if(value instanceof {{namespace}}.{{attribute.model_template}}) {
        this.{{attribute.ccif}}_ = value;
        this.dispatchAttributeChangedEvent_("{{attribute.ccif}}", previousModel_, this.{{attribute.ccif}}_);
        return true;
    }
    else
        return false;
{% else %}
    var previousValue_ = this.{{attribute.ccif}}_.getValue();
    var success_ = this.{{attribute.ccif}}_.setValue(value);
    this.dispatchAttributeChangedEvent_("{{attribute.ccif}}", previousValue_, this.{{attribute.ccif}}_.getValue());
    return success_;
{% endif %}
};



{% endfor %}
{{namespace}}.{{name}}.prototype.setValueForKey = function(key, value) {

    var returnVal_ = null;

    switch(key)
    {
{% for attribute in attributes %}
        case "{{attribute.ccif}}":
            returnVal_ = this.set{{attribute.cc}}(value);
            break;
{% endfor %}
        default:
            throw "Key: "+key+" not found in model";
    }

    return returnVal_;

};

{{namespace}}.{{name}}.prototype.getValueForKey = function(key) {

    var returnVal_ = null;

    switch(key)
    {
{% for attribute in attributes %}
        case "{{attribute.ccif}}":
            returnVal_ = this.get{{attribute.cc}}();
            break;
{% endfor %}
        default:
            throw "Key: "+key+" not found in model";
    }

    return returnVal_;

};

{{namespace}}.{{name}}.prototype.clone = function(opt_filter) {
    var json_ = this.getJSONObject(false, opt_filter);
    return new {{namespace}}.{{name}}(json_, false);
};

{{namespace}}.{{name}}.prototype.getJSONObject = function(minified, opt_filter) {

    {% if filter_namespace != None %}//check that filter is of correct type
    if(goog.isDefAndNotNull(opt_filter) && !(opt_filter instanceof {{filter_namespace}}.{{name}}))
        throw "Incorrect filter for this model";
    {% endif %}

    var jsonifiedObject_ = {};
    
    if(goog.isDef(minified) && goog.isBoolean(minified) && minified) {
    {% for attribute in attributes %}
    {% if attribute.blueprint_type == 'model' %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}().anyFieldsEnabled()) {
            if(this.get{{attribute.cc}}() == null)
                jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = null;
            else
                jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        }
        else if(!goog.isDef(opt_filter)) {
            if(this.get{{attribute.cc}}() == null)
                jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = null;
            else
                jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject();
        }
    {% elif attribute.blueprint_type == 'array' %}
    {% if attribute.element_template_is_model %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}().anyFieldsEnabled())
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject();
    {% else %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}().getJSONObject();
    {% endif %}
    {% elif attribute.blueprint_type == 'datetime' or attribute.blueprint_type == 'date' or attribute.blueprint_type == 'time' %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_.getJSONObject();
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.{{attribute.ccif}}_.getJSONObject();
    {% else %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}()
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_[{{namespace}}.{{name}}.REWRITE_MAP["{{attribute.name}}"]] = this.get{{attribute.cc}}()
    {% endif %}
    {% endfor %}
    }
    else {
    {% for attribute in attributes %}
    {% if attribute.blueprint_type == 'model' %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}().anyFieldsEnabled()) {
            if(this.get{{attribute.cc}}() == null)
                jsonifiedObject_["{{attribute.name}}"] = null;
            else
                jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        }
        else if(!goog.isDef(opt_filter)) {
            if(this.get{{attribute.cc}}() == null)
                jsonifiedObject_["{{attribute.name}}"] = null;
            else
                jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject();
        }
    {% elif attribute.blueprint_type == 'array' %}
    {% if attribute.element_template_is_model %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}().anyFieldsEnabled())
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject();
    {% else %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject(opt_filter.get{{attribute.cc}}());
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}().getJSONObject();
    {% endif %}
    {% elif attribute.blueprint_type == 'datetime' or attribute.blueprint_type == 'date' or attribute.blueprint_type == 'time' %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_.getJSONObject();
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_["{{attribute.name}}"] = this.{{attribute.ccif}}_.getJSONObject();
    {% else %}
        if(goog.isDef(opt_filter) && opt_filter.get{{attribute.cc}}())
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}()
        else if(!goog.isDef(opt_filter))
            jsonifiedObject_["{{attribute.name}}"] = this.get{{attribute.cc}}()
    {% endif %}
    {% endfor %}
    }

    return jsonifiedObject_;
};

{{namespace}}.{{name}}.prototype.getJSONString = function(minified, opt_filter) {
    return goog.json.serialize(this.getJSONObject(minified, opt_filter));
};