Skip to content

Instantly share code, notes, and snippets.

@evagoras
Last active September 30, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evagoras/bbef5123154f3fccde5d to your computer and use it in GitHub Desktop.
Save evagoras/bbef5123154f3fccde5d to your computer and use it in GitHub Desktop.
ColdBox Bean to JSON
// all tasks to be returned
var arrTasks = [];
// single task bean to be populated
var oTask = wirebox.getInstance("Task");
// example of a set method
oTask.setCode( "whatever" );
// add bean to array
arrayAppend( arrTasks, oTask );
//return as JSON
event.renderData( type="JSON", data=arrTasks );
/*
JSON result:
[{"CONSTRAINTS":{},"$MIXED":true,"Code":"whatever"}]
*/
// transient bean
component accessors="true" {
// properties
property name="Code" type="string";
// validation
this.constraints = {
};
function init(){
return this;
}
}
@evagoras
Copy link
Author

A simplistic way to show that CONSTRAINTS and $MIXED get added to the JSON response of a bean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment