【问题标题】:How to WDDX ColdFusion struct and maintain pointers or recursion如何 WDDX ColdFusion 结构和维护指针或递归
【发布时间】:2023-04-04 15:10:01
【问题描述】:

我正在使用 WDDX 将 ColdFusion 结构存储在数据库中,并且我想维护指针。这是一个示例(抱歉,速记符号可能充满错误,因为我几乎从不使用它):

tshirt={color={selected="red",options=["red","blue","yellow","white"]}};
tshirt.front= {colors=tshirt.color,design="triangle",ink="green"};
tshirt.back= {color=tshirt.color,design="square",ink="black"};

现在,tshirt.front.colortshirt.back.colortshirt.color 都是指向同一个结构的指针。如果我将 tshirt.color.selected 更改为“蓝色”,tshirt.back.color.selectedtshirt.front.color.selected 将也是“蓝色”。

但是,假设我 WDDX tshirt 然后 unWDDX 它。当我将 tshirt.color.selected 更改为“白色”时,tshirt.front.color.selectedtshirt.back.color.selected 不会更改.

谁能建议另一种方法来序列化和反序列化数据以保留指针?

到目前为止我一直在研究的几个链接:

【问题讨论】:

    标签: pointers struct coldfusion coldfusion-9 wddx


    【解决方案1】:

    使用ObjectSave(),CF9 中的新功能:

    说明

    转换 ColdFusion 数组、CFC、DateTime 对象、Java 对象、查询、 或构造成可序列化的二进制对象,并可选择保存 文件中的对象。

    退货

    对象的可序列化二进制表示。

    <cfscript>
        shirtdata = objectSave(tshirt);
        tshirt2 = objectLoad(shirtdata);
    
        tshirt2.color.selected = "blue";
        writeOutput(tshirt2.front.colors.selected);  // "blue" => reference kept
    </cfscript>
    

    现场演示:http://www.trycf.com/scratch-pad/pastebin?id=L0g211aD

    【讨论】:

    • 我很好奇它在向后兼容性方面的表现如何。听起来它是基于使用 serialVersionUID 的 java 模型。如果您更改版本,并且序列化类的 uid 值发生更改,您将无法在新版本中反序列化对象。希望 CF 考虑到这一点。
    • 我做了一个从 cf9 到 cf10 和从 cf10 到 cf9 的测试,它们都工作正常。
    • @jessieloo - 刚刚看到你的评论。您是否为 CF9 和 10 使用相同的 jvm 版本?
    • @Leigh,它们不是同一个 jvm 版本。 CF10 为 1.7.0_51_b13,CF9 为 1.6.0_17_b04
    猜你喜欢
    • 2015-06-16
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    相关资源
    最近更新 更多