AS3 Date 未使用 BlazeDS 序列化为 Java Date
当我使用 BlazeDS 传递包含日期变量的 Actionscript 值对象时,它没有正确地作为 java.util.Date 对象进行传输。当在 Java 端调用 setBaseDate 函数时,baseDate 值为 NULL。奇怪的是,如果我将 Java 端的变量重命名为 private Date date; 并创建一个 public void setDate(Date date) 函数,它就可以工作。问题是我需要传递两个不同的日期,所以我不能使用这个解决办法。
有谁知道我做错了什么?
这是我的 2 个课程:
AS3
package com.shua.flex.valueobjects
{
[Bindable]
[RemoteClass(alias='com.shua.valueObjects.myVO')]
public class myVO
{
public var label:String;
public var endDate:Date;
public var baseDate:Date;
public function myVO()
{
super();
}
}
}
Java:
package com.shua.valueObjects;
import java.util.Date;
public class myVO{
public static String NAME = "myVO";
private String label;
private Date endDate;
private Date baseDate;
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public void setEndDate(Date endDate) {
this.endDate= endDate;
}
public Date getEndDate() {
return this.endDate;
}
public void setBaseDate( Date baseDate ){
this.baseDate = baseDate;
}
public Date getBaseDate(){
return this.baseDate;
}
}
When I pass a Actionscript Value Object that contains a Date variable using BlazeDS it is not getting transferring as a java.util.Date object correctly. When the setBaseDatefunction gets called on the Java side the baseDate value is NULL. The weird thing is if I rename the variable on the Java side to private Date date;
and create a public void setDate( Date date)
function it works. The problem is I need to pass 2 different dates so I can't uses this work around.
Does anyone know what I'm doing wrong?
Here are my 2 classes:
AS3
package com.shua.flex.valueobjects
{
[Bindable]
[RemoteClass(alias='com.shua.valueObjects.myVO')]
public class myVO
{
public var label:String;
public var endDate:Date;
public var baseDate:Date;
public function myVO()
{
super();
}
}
}
Java:
package com.shua.valueObjects;
import java.util.Date;
public class myVO{
public static String NAME = "myVO";
private String label;
private Date endDate;
private Date baseDate;
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public void setEndDate(Date endDate) {
this.endDate= endDate;
}
public Date getEndDate() {
return this.endDate;
}
public void setBaseDate( Date baseDate ){
this.baseDate = baseDate;
}
public Date getBaseDate(){
return this.baseDate;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在同一个类中发送多个 Date 对象应该不是问题。
您确定 getter 或 setter 中没有小错误吗?您是否同时拥有该属性的 getter 和 setter?
Sending several Date objects in the same class should not be a problem.
Are you sure you don't have a small error somewhere in the getter or the setter? Do you have both a getter and a setter for the property?
您可以尝试:
You could try:
问题是java对象中的静态字符串。我想这些类需要完全匹配才能使序列化自动工作。因此,只需删除静态名称即可解决问题。
The problem was the static string in the java object. I guess the classes need to match exactly for the serialization to automatically work. So just removing the static name fixes the issue.