Thursday, August 27, 2015

ColdFusion UDF ( JSONUtil ) for serialize complex Objects without changing data formatting

ColdFusion has built-in function  SerializeJSON for serialize a complex object into JSON but many times our data gets converted into some different format. Example:

- if a number is greater than certain limit then it will convert it into exponent format.
- if the data type is date then it converted to some type but in UI side we want something different.
- Sometimes decimal fields also gets converted to some other formatting.


So, in-order to avoid any reformatting of data at client side. I wrote a ColdFusion function which will perform the conversion (CF Object -> JSON). I'm already using this in one of my project and it works fine without any problem. Hope it may help you if you're looking something like this.

Points to Remember:
- You can modify the code if you need certain type of formatting for date or number data type.
- For serializing ColdFusion components make sure the fields present as the properties of that component.

If you have any feedback for this I'm happy to listen it. Below is the code:

Followers