renderData as JSON and null values

Hi guys,

I’m running into a issue when attempting to renderData back as JSON or XML This is the error I get:

Error Type: Expression : [N/A]
Error Messages: Element HOME_TELEPHONE is undefined in a CFML structure referenced as part of an expression.

Tag Context:
ID: ??
LINE: 310
Template: /Library/WebServer/Documents/coldbox/system/core/conversion/JSON.cfc
LINE: 310

In my database, home_telephone is NULL. If I dump the home_telephone out within a view it’s value is empty (undefined), however whenever CB comes across any empty value in my return structure, it throws the above error with the corresponding empty variable name.

Below is the code of my Handler. I’m also using CF ORM to load the User Entity within UserService.

Any help on this one is greatly appreciated. I’ve been banging my head against the desk for a couple of hours now.




  • REST User Handler
    component extends=“coldbox.system.EventHandler” output=“false”{

property name=“userService” inject;

this.prehandler_only = “”;
this.prehandler_except = “”;
this.posthandler_only = “”;
this.posthandler_except = “”;
//REST Allowed HTTP Methods Ex:
this.allowedMethods = {index=‘GET’,createUser=‘POST’,updateUser=‘PUT’,removeUser=‘DELETE’};
this.allowedMethods = {};

void function preHandler(event,currentAction) output=“false”{
var rc = event.getCollection();
event.paramValue(“format”, “json”);
rc.return = {error=false,data="",messages=""};
log.debug(“New REST call: #event.getCurrentRoute()#”,rc);

void function postHandler(event,currentAction) output=“false”{
var rc = event.getCollection();

void function invalid(event) output=“false”{
var rc = event.getCollection();
rc.return.error = true;
rc.return.messages = “Invalid REST call”;
if( NOT reFindNoCase("^(json|xml)",event.getValue(“format”,"")) ){
rc.return.messages = “Invalid format detected or not passed: #event.getValue(“format”,”")#";
rc.format = “xml”;

/void function onError(event,action,exception) output=“false”{
var rc = event.getCollection();
rc.return.error = true;
rc.return.messages = “The requested resource #event.getCurrentRoute()# produced an error. #exception.message# #exception.detail#”;

function index(event){
var rc = event.getCollection();
//prepare the user object to be returned
var user = structNew();
var address = structNew();
var qUser = userService.getUser(25,true); = qUser.getUserID();
user.firstname = qUser.getFirstName();
user.firstname = qUser.getFirstName(); = qUser.getEmail();
user.account_type = qUser.getFK_AccountTypeID();
user.date_subscription_end = “”;
user.home_telephone = qUser.getHomeTelephone();
user.mobile_telephone = qUser.getMobileTelephone();
user.work_telephone = qUser.getWorkTelephone();
user.gender = qUser.getAttribute().getGender();
user.birthdate = qUser.getAttribute().getBirthDate();
user.blood_type = qUser.getAttribute().getFK_BloodTypeID();
user.photo_url = qUser.getAttribute().getPhoto();
user.eye_color = qUser.getAttribute().getFK_EyeColorID();
user.hair_color = qUser.getAttribute().getFK_HairColorID();
user.height = qUser.getAttribute().getHeight();
user.weight = qUser.getAttribute().getWeight();
user.user_language = qUser.getAttribute().getUserLanguage();
user.addres = address;

var = user;

function creatUser(event){
var rc = event.getCollection();

function updateUser(event){
var rc = event.getCollection();

function removeUser(event){
var rc = event.getCollection();

function onMissingAction(event,missingAction){


Not that this is helpful to you, sorry, I’m just trying to learn and understand

Typically in CF, NULL in the db comes through as empty string, since CF doesn’t have null values. The only undefined results I’m aware of are variables that haven’t been defined, the result of a java function that returns a real null, or the result of a CF function that doesn’t return anything.

Does ColdBox do something different with db NULL values that I should be aware of?


Hi Dave,

In this case the db field value is empty (nothing has been committed to the field in the database). If I were to simply output qUser.getAttribute().getHomeTelephone() the output would be empty, with no errors. It’s only when I try to return the set values of the array as a JSON structure (via CB) that the error is produced. Has anyone else experienced this? I’m not sure if it matters, but I’ve set default="" on the properties in my entity that have the empty values.