Last active
September 30, 2015 09:14
-
-
Save evagoras/bbef5123154f3fccde5d to your computer and use it in GitHub Desktop.
ColdBox Bean to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"}] | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// transient bean | |
component accessors="true" { | |
// properties | |
property name="Code" type="string"; | |
// validation | |
this.constraints = { | |
}; | |
function init(){ | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simplistic way to show that CONSTRAINTS and $MIXED get added to the JSON response of a bean.