如何告诉 java.beans.Introspector 忽略 getter 方法?
我有一个由两个值组成的字段。这是与 JSON 进行序列化的字段,效果很好。
public String getRevisions() { return revisions; }
public void setRevisions(String revisions) { this.revisions = revisions; }
我添加了两个辅助方法来检索单独的值,但我不希望它们序列化为 JSON。
public String getCurrentRevision() { ... return first revision ... }
public String getPreviousRevision() { ... return second revision ... }
有没有办法让我在通过 getBeanInfo() 构建 BeanInfo 时告诉 java.beans.Introspector 忽略这些额外的 getter?注释会很可爱,我真的希望避免必须手动创建我自己的 BeanInfo 。
I have one field which is a composition of two values. This is the field that gets serialized to/from JSON and works great.
public String getRevisions() { return revisions; }
public void setRevisions(String revisions) { this.revisions = revisions; }
I added two helper methods to retrieve the separate values, but I don't want them serialized to JSON.
public String getCurrentRevision() { ... return first revision ... }
public String getPreviousRevision() { ... return second revision ... }
Is there a way I can tell java.beans.Introspector
to ignore these additional getters when building the BeanInfo
via getBeanInfo()
? An annotation would be lovely, and I'm really hoping to avoid having to manually create my own BeanInfo
for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许可以尝试使用 beans API 中的注释: http:// download.oracle.com/javase/7/docs/api/java/beans/Transient.html
他们建议您将其实际放置在 getter 上,这样看起来就符合要求。
编辑:哎呀,刚刚注意到这是在 Java 7 中引入的。因此,如果您想使用它,您需要确保它在最新的 JRE 中运行。
Maybe try this annotation from the beans API: http://download.oracle.com/javase/7/docs/api/java/beans/Transient.html
They advice you to actually place it on the getter, so that seems to fit the bill.
EDIT: oops, just noticed this was introduced in Java 7. So you're gonna need to make sure this runs in a very recent JRE if you want to use it.