序列化复杂对象 ORM 实体处理关系实体
在 ColdFusion 9 中,我正在序列化一个 ORM 实体。但这样做时,它缺少关系实体。
ColdFusion 用于将复杂对象转换为 JSON 表示法的 serializeJSON()
方法似乎无法在 ORM 对象上正常工作。在 ORM 对象上使用 serializeJSON()
时,不会返回任何具有作为其他对象数组属性的对象!
以前有人解决过此类问题吗?你是怎么处理的?
谢谢。
In ColdFusion 9 I am serializing an ORM entity. When doing this, though, it's missing relational entities.
The serializeJSON()
method ColdFusion uses to convert complex objects into JSON notation doesn’t seem to work correctly on ORM objects. Any object that had a property that was an array of other objects is not returned when using serializeJSON()
on ORM objects!
Has anyone tackled this sort of issue before? How did you handle it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题解决了!这不是一个错误,您必须将 remotingFetch 设置为 true!默认情况下,对于具有一对一、一对多、多对一或多对多关系的属性,它设置为 false。
Issue resolved! This is not a bug you have to set remotingFetch to true! By default it is set to false for properties with one-to-one, one-to-many, many-to-one, or many-to-many relationships.
我在远程方法中遇到了类似的问题,并提出了一个递归函数,它将内省您的 CFC 并发送回您需要的属性。您可以(使用 CFC 上的属性)指定要返回和不希望返回的属性。实际上,您可以通过属性“组”来完成此操作,因此您可以将“id”和“name”分配给“compact”组,并将CFC 中的其余属性分配给“full”组。它还将处理序列化嵌套组件(ORM 或其他)。另一个大优点是 Adobe 的序列化方法不会序列化继承对象的属性。因此,如果您有父对象,则序列化时将无法取回这些属性。我的 toSerialized() 方法解决了这个问题。
看看:http://www.justcodefaster。 com/blog/2012/07/toserialized-method-for-coldfusion-objects/
I've run into similar issues with remote methods and came up with a recursive function that will introspect your CFC and send back the properties you need. You can specify (with attributes on the CFC) which properties you do and don't want to return. Actually, you can do it by "groups" of properties, so you could assign "id" and "name" to the "compact" group and the rest of the properties in your CFC to the "full" group. It will also handle serializing nested components (ORM or otherwise). The other big advantage is that Adobe's serialization methods do not serialize properties from inherited objects. So if you have a parent object, you will not get those properties back when serialized. My toSerializable() method solves that.
Check it out: http://www.justcodefaster.com/blog/2012/07/toserializable-method-for-coldfusion-objects/