How to ignore certain object properties when serializing into JSON?

Let’s say I have a component with 2 properties

<cfcomponent name="Thing">
    <cfproperty name="property1" type="numeric" />
    <cfproperty name="property2" type="numeric" />

I want to be able to serialize this component using serializeJSON()

How would I ensure that property1 is included in the JSON and not property 2 ?

I tried what I thought must be it by setting serializable=“false” on property 2, but that does not seem to apply when serializing the object as JSON.

My next approach was to create my own function on the object named “toJSON()” that filtered the properties by their serializable setting and only serialized those where it was true. This works great for shallow properties, but sometimes I have properties that are another object and I need to ensure the properties on that object are also not serialized. Before I get into creating a recursive function to solve this problem, I wonder if this is even the best way?

For reference, .NET has a [JsonIgnore] attribute that can be used to achieve this. I basically want the same behaviour.

Seems a good idea for Lucee 6

1 Like

Possibly in the short term it’s also worth clarifying in the docs that the “serializable” attribute has nothing to do with JSON serialization.

Hmm, just looked and the Lucee docs actually don’t even mention serializable as a valid attribute of cfproperty. CFDocs doesn’t mention that Lucee doesn’t support this attribute though. Would the serializable attribute actually do what I wanted in Adobe CF?