json - ColdFusion9: Using serializeJson on Hibernate entity encodes numeric properties as strings -



json - ColdFusion9: Using serializeJson on Hibernate entity encodes numeric properties as strings -

i'm writing first orm-backed rest api, , having issues json serialization. here's 1 of entity definitions:

component persistent="true" extends="base" { property name="id" fieldtype="id" generator="native" ormtype="int" type="numeric"; property name="relationship" type="string" ormtype="string"; property name="comment" type="string" ormtype="text"; //related entities property name="terma" cfc="term" fieldtype="many-to-one" fkcolumn="terma" lazy="false"; property name="termb" cfc="term" fieldtype="many-to-one" fkcolumn="termb" lazy="false"; //override getmemento include appropriate relationships public struct function getmemento(){ //standard stuff local.memento = super.getmemento(); //custom add-ons local.memento["terma"] = this.getterma().getid(); local.memento["termb"] = this.gettermb().getid(); homecoming local.memento; } }

this base of operations entity extends (for super.getmemento among other things):

component extends="core.v1.models.base" { public struct function getmemento(){ local.memento = deserializejson(serializejson(this)); //fix numerics showing strings if (structkeyexists(local.memento, "id")){ local.memento.id = javacast("int", local.memento.id); } homecoming local.memento; } public array function transformcollectionintomementos(array input){ if (arraylen(arguments.input) > 0){ (var = 1; <= arraylen(arguments.input); i++){ arrayset(arguments.input,i,i,arguments.input[i].getmemento()); } } homecoming arguments.input; } }

the class this 1 extends isn't relevant here.

finally, here's simplified version of code renders json representation of data:

<cfoutput>#serializejson(transform(entityload("interaction")))#</cfoutput> public array function transform(array input){ if (arraylen(arguments.input) > 0){ (var = 1; <= arraylen(arguments.input); i++){ arrayset(arguments.input,i,i,arguments.input[i].getmemento()); } } homecoming arguments.input; }

you can see in getmemento() implementation in 2nd code snippet i'm attempting resolve javacasting value of id properties (each entity has property named "id") integer. doesn't work. i've tried javacast("int", local.memento.id * 1); , doesn't work either.

no matter i've tried, resulting json looks this:

[{"termb":"2","terma":"1","id":"1","relationship":"+"},{"termb":"4","terma":"1","id":"3","relationship":"-"}]

what i'm expecting this:

[{"termb":"2","terma":"1","id":1,"relationship":"+"},{"termb":"4","terma":"1","id":3,"relationship":"-"}]

i'm @ loss. missing? why doesn't work?

is alter adobe made serializejson?

http://coldfusion.tcs.de/adobe-please-fix-coldfusion-serializejson/

json hibernate serialization coldfusion

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -