BlazeDS 将 Java Float 编组为 ActionScript int

发布于 2024-11-16 11:03:19 字数 785 浏览 4 评论 0原文

我正在使用 BlazeDS 将 Java 对象编组到 Flex。我看到的是,如果 Java Float 包含整数值(整数,例如 123),那么它会被编组为 ActionScript int。我希望 Java Float 总是被编组为 ActionScript Number 作为 记录在 BlazeDS 开发人员指南中。

有没有办法配置这个或者这只是 BlazeDS 的错误?

后续:浮动包含在地图内。传递给 BlazeDS 的 Java 映射看起来像这样:

Map map = new HashMap();
Float f = 123.0;
map.put("number", f);

当它到达 Flex 端时 map 是一个 Object

var map:Object = ...
trace(map.number);
trace(getQualifiedClassName(map.number));

prints:

123
int

所以它正确地序列化了值,就像类型错误。

I'm using BlazeDS to marshall Java objects to Flex. What I'm seeing is that if a Java Float holds a integer value (whole number, such as 123), then it gets marshalled to a ActionScript int. I would expect that a Java Float always gets marshalled to an ActionScript Number as documented in the BlazeDS Developer Guide.

Is there a way to configure this or is this just a BlazeDS bug?

Follow-up: The float is contained within a map. The Java map that is being passed to BlazeDS looks something like:

Map map = new HashMap();
Float f = 123.0;
map.put("number", f);

When it arrives on the Flex side map is an Object:

var map:Object = ...
trace(map.number);
trace(getQualifiedClassName(map.number));

prints:

123
int

So it's serializing the value correctly, just as the wrong type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙幽之幻 2024-11-23 11:03:19

这与 BlazeDS 本身无关。这是 AS3 的“功能”。

这将有助于理解正在发生的事情。或者让你更加困惑...

第一件事:**JAVA:java.lang.Float 和 float ==> AS3:数字 **

var number:Number = 4.5;
trace(typeof(number) == "number");      //true
trace(number is Number);                //true

var integer:int = 2;
trace(typeof(integer) == "number");     //true!
trace(integer is Number);               //true!

//number=4.5
trace(number is int);                   //false
trace(getQualifiedClassName(number));   //Number

//Here comes the fun..
number=number-0.5; //number=4
trace(number is int);                   //true!!
trace(getQualifiedClassName(number));   //int!!

希望这确实有帮助!

This has nothing to do with BlazeDS itself. It's a AS3 "feature"..

This will help understanding what's going on. Or confuse you even more...

First thing: **JAVA: java.lang.Float and float ==> AS3: Number **

var number:Number = 4.5;
trace(typeof(number) == "number");      //true
trace(number is Number);                //true

var integer:int = 2;
trace(typeof(integer) == "number");     //true!
trace(integer is Number);               //true!

//number=4.5
trace(number is int);                   //false
trace(getQualifiedClassName(number));   //Number

//Here comes the fun..
number=number-0.5; //number=4
trace(number is int);                   //true!!
trace(getQualifiedClassName(number));   //int!!

Hope this actually helped!

私野 2024-11-23 11:03:19

AS3/Java 值对象中的变量名称是否相同?

在具有 RemoteClass 标签的值对象中,
AS3

public var myfloat:Number;

Java

public float myfloat = 10.4f;

有关精确信息:请参阅此帖子:
如何处理 Actionscript 中的数字精度?

Are the variable names same in AS3/Java value objects?

In the value object , that has RemoteClass tag,
AS3

public var myfloat:Number;

Java

public float myfloat = 10.4f;

For precision info: Look at this post:
How to deal with Number precision in Actionscript?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文