Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:21:05+00:00 2026-05-23T14:21:05+00:00

I’m writing my first ORM-backed REST api, and having some issues with the JSON

  • 0

I’m writing my first ORM-backed REST api, and having some issues with the JSON serialization. Here’s one of my 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 to 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();

        return local.memento;
    }

}

This is the Base entity it 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 up as strings
        if (structKeyExists(local.memento, "id")){
            local.memento.id = javacast("int", local.memento.id);
        }
        return local.memento;
    }

    public array function transformCollectionIntoMementos(array input){
        if (arrayLen(arguments.input) > 0){
            for (var i = 1; i <= arrayLen(arguments.input); i++){
                arraySet(arguments.input,i,i,arguments.input[i].getMemento());
            }
        }
        return arguments.input;
    }
}

The class that this one extends isn’t relevant here.

Finally, here’s a simplified version of the code that renders the json representation of the data:

<cfoutput>#serializeJson(transform(entityLoad("interaction")))#</cfoutput>

public array function transform(array input){
    if (arrayLen(arguments.input) > 0){
        for (var i = 1; i <= arrayLen(arguments.input); i++){
            arraySet(arguments.input,i,i,arguments.input[i].getMemento());
        }
    }
    return arguments.input;
}

You can see in the getMemento() implementation in the 2nd code snippet that I’m attempting to resolve this by javacasting the value of all ID properties (each entity has a property named “id”) to an integer. This doesn’t work. I’ve also tried javacast("int", local.memento.id * 1); and that doesn’t work either.

No matter what I’ve tried, the resulting json looks like this:

[{"termB":"2","termA":"1","id":"1","relationship":"+"},{"termB":"4","termA":"1","id":"3","relationship":"-"}]

What I’m expecting is this:

[{"termB":"2","termA":"1","id":1,"relationship":"+"},{"termB":"4","termA":"1","id":3,"relationship":"-"}]

I’m at a loss. What am I missing? Why doesn’t this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:21:05+00:00Added an answer on May 23, 2026 at 2:21 pm

    Is it the change that Adobe made to serializeJSON?

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.