Flex blazeds/lcds AMF 瞬态变量序列化

发布于 2024-12-03 08:26:43 字数 947 浏览 3 评论 0原文

我正在使用 LCDS 和 Flex。 当我将一个对象从 java 发送到 Flex 时,我不想发送所有属性。据我所知,如果您不想序列化,请创建一个瞬态变量。

例如。

 private transient Date birthDate;

 public Date getBirthDate(){  
    return birthDate;
 }

 public void setBirthDate(Date val){
    birthDate = val;
    //Some code here.
 }

现在序列化对象中不应包含birthDate。但是当我看到 AMF 日志时,该对象具有包含值的birthDate。
序列化是否会检查代码并检查私有变量是否是瞬态的。(我不明白它如何访问私有财产。我有点困惑。)
我应该将变量标记为公共吗?那么 getter 和 setter 就没有意义了,而且我在 setter 方法中编写了一些代码。所以我需要二传手。

问题:

  1. 我在一本书中读到(Brain Telintelo 的 Enterprise Flex with blazeds,第 15 章),开箱即用的 Blazeds 仅序列化具有匹配的 getter 和 setter 的文件。如果是这种情况,will blazeds 甚至会费心将私有财产检查为瞬态。

  2. 有人可以解释一下正常的序列化(不是amf序列化)是如何发生的,并跟踪私有瞬态变量,即使它们有公共的getter和setter。

    有人
  3. 如何使 java 变量在 Flex/LCDS/BlazeDS 环境中不序列化。

我的对象中有 50-60 个变量,其中 4 或 5 个变量不应该被序列化。所以在这么大的对象中编写custionSerializer是一个很大的痛苦。我看到的另一个缺点是,如果我编写自己的序列化程序,hibernate 将无法使用该对象。

I am using LCDS and Flex.
When I am sending an object from java to Flex, I donot want to send all the properties. As far as I know, if you do not want to serialize make a variable transient.

eg.

 private transient Date birthDate;

 public Date getBirthDate(){  
    return birthDate;
 }

 public void setBirthDate(Date val){
    birthDate = val;
    //Some code here.
 }

Now the serialized object should not have birthDate in it. But When I see the AMF logs , the object has the birthDate with value in it.
Does serialization looks into code and checks the private variable is transient.( I don't understand how it has access to private property. I am little confused.)
Should I mark variable as public. Then getters and setters make no sense and moreover I write some code in setter method. So I need setter.

Questions:

  1. I read in a book(Enterprise flex with blazeds by Brain Telintelo, Chapter 15) that out of box Blazeds only serializes fileds that have matching getters and setters. If this is the case, will blazeds even bothers to check private property as transient.

  2. Can some body please explain how normal serializtion( not amf serializtion ) takes place and keeps track of private transient variables even though they have public getters and setters.

  3. How do I make a java variable not serialize in Flex/LCDS/BlazeDS environment.

I have 50-60 variables in objects and 4 or 5 varibales should not be seriablezed. So writing custion Serializer in such a large objects is a big pain. And another disadvantage I see is hibernate will not be able to use this object if I write my own serializer.

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

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

发布评论

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

评论(3

街道布景 2024-12-10 08:26:43

我通常使用 Granite Data Services(而不是 LCDS 或 Blaze),但是您尝试过使用 [Transient] ActionScript 标签吗? (当然,如果您生成 .as 类,这可能是一个问题 - 也许有一个 @Transient 注释?)

http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html

其工作方式取决于谁(什么)正在做什么序列化。例如,我认为 Granite 的行为与 Blaze 略有不同。我不认为 Granite 序列化私有属性(可能是记错了)。我还记得几年前,我为 Granite 创建了一个自定义序列化类,它告诉它忽略带有“transient”Java 关键字的字段(使用反射)。

我不知道您是否可以在 Blaze/LCDS 中实现自定义序列化逻辑(同样容易),但这可能也值得研究。这并不是一个巨大的痛苦(正如你所说),因为它只是我定制的一个类,但我再次确定这对于 Granite 来说很简单。

可能有一两个辅助库可以用于此目的。写的人写了这个 http ://www.flexpasta.com/index.php/2008/05/19/blazeds-with-annotations-for-remote-objects/ 似乎正在做你所要求的事情相反。 (没有 setter 时强制序列化。)

I usually use Granite Data Services (rather than LCDS or Blaze), but have you tried using the [Transient] ActionScript tag? (Of course if you're generating your .as classes, this might be an issue - perhaps there's a @Transient annotation?)

http://livedocs.adobe.com/flex/3/html/help.html?content=metadata_3.html

The way this works depends on who (what) is doing the serialization. For example Granite, I believe, behaves slightly differently than Blaze. I don't think Granite serializes private attributes (could be recalling this wrong). Also I do recall a few years back, I created a custom serialization class for Granite which tells it to ignore fields with the 'transient' Java keyword (using reflection).

I don't know if you can implement custom serialization logic in Blaze/LCDS (just as easily) but that might be something worth looking into as well. It wasn't a huge pain (as you say) because it was just a single class that I customized, but again I only know for sure that this is simple w/Granite.

There may be a helper lib or two out there for this. The guy wrote wrote this http://www.flexpasta.com/index.php/2008/05/19/blazeds-with-annotations-for-remote-objects/ appears to be doing what you're asking in reverse. (Force serialization when no setter.)

甜嗑 2024-12-10 08:26:43

如果你想排除一个Java属性被序列化到Flex,这里有一篇关于同一问题的帖子:https://stackoverflow.com /a/22328869/244911

if you want to exclude one Java properties from being serialized to Flex, here is a post to the same question : https://stackoverflow.com/a/22328869/244911

忘你却要生生世世 2024-12-10 08:26:43

把 [Transient] 放在 getter 上就足够了,放在 setter 上是多余的,多余的,会导致编译器警告。

It is enough to put [Transient] on getter, putting it on setter is redundant and redundant and will resunt in a compiler warning.

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