event.RenderData bug?

Hi guys,

I think I may have uncovered a bug in event.RenderData. I have a model which has a getter called getPayload(). For the most part this returns text - i.e chat messages that someone has sent to another person. The problem occurs when the message someone typed is "Yes" or "No".

The problem that is occurring is event.renderData is then converting "Yes" into a boolean (true), which is then being converted to 1 or 0 in the final app. There might be a way for me to get around this by modifying the getter in the model, but wondering if anyone else can confirm this behavior? Note: I did a quick dump to logbox prior to running event.RenderData and the value dumped out as "Yes".

Thanks.

Nolan

is this when marshalling to json or xml?

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I have only tested this when marshalling to JSON. I will check XML now.

Nolan

Marshalling to XML returned the string value of “Yes”, so it appears it’s only JSON that has the issue.

Nolan

Ok, I am guessing it converts yes to boolean in the json converter?

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

true :wink:

and it converts No to false.

Are you doing

Value: yes (Should be transformed to true)

Or

Value:’yes’ (Should never be transformed to true)

When it is being converted in JSon?

Regards,

Andrew Scott

http://www.andyscott.id.au/

Hi Andrew,

The contents of Payload in the DB could be any string... i.e "foo", "yes", "no", "this is my message"

it's only when the value in the DB is "yes" or "no" that it is being converted to true or false. it's being converted to JSON in my postHandler. the value returned from getPayload() returns a string with a value of "yes" (the value that was in the db) and event.RenderData as JSON is what is is converting it to a boolean as opposed to treating the value as a string

Thanks

Nolan

The problem is that CF treats this as a true:

isBoolean( “yes” )

So it evaluates to booleans, tough on a typeless language. So even if you do this:

a = { canceled = “yes” }

serializeJSON( a )

You end up with: {“CANCELED”:true}

This is a tough one.

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

I understand. I found a way…errr…hack to get around it by evaluating the value of getPayload(). If it returns “yes” or “no” I add a space "yes " / "no " and then it is not treated as a boolean.

This is not the most elegant way to get around this issue, but it works for now. Any other suggestions are appreciated, but at least I have it working now.

Thanks.

Nolan

Ha, I was just going to suggest that hack as I have done it before. Glad you got a work around.

Curt

Since these are chat messages I would apply your hack to each message instead of just Y/N. At least then it wont be a hack and will be common among all messages :slight_smile:

Hi Aaron,

Good point, however the payload field holds more than just text. The model for the data is an Event object. Event Objects have event types, and a type could be text message or a type could be photo. If it were photo the Payload field would contain the Base64 value of the photo. So essentially I need to narrow the hack down to just Y/N otherwise I’m adding extra data to payloads.

Thanks.

Nolan