Serialization 在Play框架中将UUID用作操作参数

Serialization 在Play框架中将UUID用作操作参数,serialization,playframework,uuid,Serialization,Playframework,Uuid,我想使用UUID作为操作参数。但是,除非在生成动作URL时对UUID对象使用.toString(),否则Play似乎会以不同的方式序列化对象;类似这样的内容:referenceId.sequence=-1&referenceId.hashCode=1728064460&referenceId.version=-1&referenceId.variant=-1&referenceId.timestamp=-1&referenceId.node=-1 然而,使用toString“有效”,但是当我通过

我想使用UUID作为操作参数。但是,除非在生成动作URL时对UUID对象使用.toString(),否则Play似乎会以不同的方式序列化对象;类似这样的内容:referenceId.sequence=-1&referenceId.hashCode=1728064460&referenceId.version=-1&referenceId.variant=-1&referenceId.timestamp=-1&referenceId.node=-1

然而,使用toString“有效”,但是当我通过直接调用该方法从一个操作重定向到另一个操作时,我无法调用toString,因为该方法需要UUID。因此,它给了我上面所示的表示


有什么方法可以将特定类型的序列化相交吗?

您不能在操作参数中仅使用字符串吗?您知道这个字符串是一个UUID,所以您总是可以从中重新创建UUID。也许这不是你的解决方案,但这是我的第一个想法。据我所知,play在通过这些对象时会序列化这些对象。
如果这对您不起作用,请尝试在此处查找:

您不能在操作参数中仅使用字符串吗?您知道这个字符串是一个UUID,所以您总是可以从中重新创建UUID。也许这不是你的解决方案,但这是我的第一个想法。据我所知,play在通过这些对象时会序列化这些对象。
如果这对您不起作用,请尝试在此处查找一些内容:

我找到了一种方法来实现这一点,但现在这意味着要对框架代码本身的一部分进行黑客攻击

您基本上需要的是一个TypeBinder,用于将字符串中的值绑定到UUID 和一个小的代码更改 play/framework/src/play/data/binding/Unbinder.java

    if (!isAsAnnotation) {
        // We want to use that one so when redirecting it looks ok. We could as well use the DateBinder.ISO8601 but the url looks terrible
        if (Calendar.class.isAssignableFrom(src.getClass())) {
            result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format(((Calendar) src).getTime()));
        } else {
            result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format((Date) src));
        }
    }
}
//here's the changed code
else if (UUID.class.isAssignableFrom(src.getClass()))
{
   result.put(name, src.toString());
}
else {
// this code is responsible for the behavior you're seeing right now
        Field[] fields = src.getClass().getDeclaredFields(); 
        for (Field field : fields) {

            if ((field.getModifiers() & BeanWrapper.notwritableField) != 0) {
                // skip fields that cannot be bound by BeanWrapper
                continue;
            }
我正在与框架作者合作对此进行修复。稍后将返回结果

如果您迫切需要,请自己将更改应用于代码,并通过发出 蚂蚁 在playframework/框架中
目录

我找到了这样做的方法,但现在它意味着对框架代码本身的一部分进行黑客攻击

您基本上需要的是一个TypeBinder,用于将字符串中的值绑定到UUID 和一个小的代码更改 play/framework/src/play/data/binding/Unbinder.java

    if (!isAsAnnotation) {
        // We want to use that one so when redirecting it looks ok. We could as well use the DateBinder.ISO8601 but the url looks terrible
        if (Calendar.class.isAssignableFrom(src.getClass())) {
            result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format(((Calendar) src).getTime()));
        } else {
            result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format((Date) src));
        }
    }
}
//here's the changed code
else if (UUID.class.isAssignableFrom(src.getClass()))
{
   result.put(name, src.toString());
}
else {
// this code is responsible for the behavior you're seeing right now
        Field[] fields = src.getClass().getDeclaredFields(); 
        for (Field field : fields) {

            if ((field.getModifiers() & BeanWrapper.notwritableField) != 0) {
                // skip fields that cannot be bound by BeanWrapper
                continue;
            }
我正在与框架作者合作对此进行修复。稍后将返回结果

如果您迫切需要,请自己将更改应用于代码,并通过发出 蚂蚁 在playframework/框架中
目录

使用字符串是可能的,但话说回来,为什么要首先使用UUID类呢?它有一个特定的格式,我不想做额外的测试等,以确保它是一个实际的UUID。使用字符串是可能的,但话说回来,为什么甚至有UUID类放在首位?它有一个特定的格式,我不想做额外的测试等,以确保它是一个实际的UUID。谢谢。看起来这可能是目前最好的答案。我没有直接调用action方法,而是对我传递的所有UUID使用redirect()和toString()来解决这个问题。因此,假设这将在以后的框架中得到处理,我可以接受它(无需更改框架代码)。谢谢你的回答:)谢谢。看起来这可能是目前最好的答案。我没有直接调用action方法,而是对我传递的所有UUID使用redirect()和toString()来解决这个问题。因此,假设这将在以后的框架中得到处理,我可以接受它(无需更改框架代码)。谢谢你的回答:)