SerializeJson and Lazy Properties (Lucee + Hibernate)

Hello everyone,

I’m working with an application that was originally built on ColdFusion. The application utilizes Hibernate ORM. There are entities that have associated properties (A property that references another entity in a certain relationship - one-to-many, many-to-many, etc). These associated properties are often marked as “lazy” for a good reason. The application has a need to send json serialized entity data to client and this is where Lucee has trouble. In ColdFusion, serializeJson seems to skip properties that are marked as “lazy”. If I examine the json data for an entity on ColdFusion server, I only see properties that aren’t associated properties. When the same entity data are serialized to Json on Lucee, I see all the child entity data as json, and certain children data are very large.

My question is… does the serializeJson function on Lucee cause retrieval of all lazy properties? Is there a way to serialize only the non-lazy properties of an entity somehow?

UPDATE: Found [LDEV-176] serializeJSON() on loaded ORM panics server - Lucee. According to this, the ACF implementation of the serializeJson function uses toString() recursively on variables and will not recurse to lazy=true relationships. It seems Lucee’s implementation recurses to lazy=true relationships too. I need to find out if there is a way to prevent this.

OS: Windows 10
Java Version: OpenJDK 11.0.7
Tomcat Version: 9.0.35
Lucee Version: 5.3.8.189

I’ve checked this issue and Yes, there is an incompatibility in lucee with the ACF SerializeJSON result. Could you please create an incompatibility ticket in jira https://luceeserver.atlassian.net/

I assume it’s not a Coldbox application, but you could checkout how Mementifier works GitHub - coldbox-modules/mementifier: This module creates memento/state representations from business objects and use parts for your own project.

Hello @cfmitrah

I created an issue https://luceeserver.atlassian.net/browse/LDEV-3652. Unfortunately, I originally created it as “Enhancement” issue type. Now, I’m trying to change the issue type to incompatibility, but I get the access denied message.

Is someone able to update the issue type of that issue I linked?

Thank you!

updated! can you provide an example?

you might want to also try out the latest 5.4.29.3-BETA

Hello @Zackster,

I made a new comment on the issue and attached a small test project as an example - https://luceeserver.atlassian.net/browse/LDEV-3652.

Thank you. I will also check out that beta.

cheers! a few little notes

test_type.cfm is missing, also event.cfc defines a datasource which it doesn’t need to

also, could you define the datasource test_orm once as variable in application.cfc so we can easily switch it?

Haha, I apologize for the confusion. test_type.cfm is another test that I’ve done in the past (This is a test project that I’ve created different things with ORM). I know index.cfm has a link referencing it, but the focus for this issue is test_serializejson.cfm. But, I will go ahead and include it.

When you say "define the datasource test_orm once as variable in application.cfc, are you talking about this?

I think I understand. I only left one datasource declaration inside the ORM settings.
I updated the issue with the new attachment.

Thank you!