我有一个autobean,它的属性只是UI所需要的。我相信您可以将值设为空,AutoBeanCodex将不会序列化该属性,但这等同于序列化时需要的额外步骤。
我希望有一些类似于Editor @Ignore注释的注释。例如:
public interface Foo {
...
@Ignore
String getUiOnlyProperty();
}因此,除了在序列化时清空该值之外,是否还有其他方法可以防止autobean属性被序列化?
发布于 2012-12-13 06:52:07
Autobeans旨在成为JSON/XML/任何格式上的Java皮肤-它们实际上并不是用来保存其他数据片段的。也就是说,一些想法要么几乎用开箱即用的工具回答了你的问题,要么可能启发一些其他关于如何解决你的问题的想法。
您应该能够通过省略setter来构建只读属性。这并不完全是您所要求的,但可能仍然很方便。
沿着这些思路,@PropertyName注释的JavaDoc似乎暗示了这个可能的特性:
/**
* An annotation that allows inferred property names to be overridden.
* <p>
* This annotation is asymmetric, applying it to a getter will not affect the
* setter. The asymmetry allows existing users of an interface to read old
* {@link AutoBeanCodex} messages, but write new ones.
*/阅读旧的消息但编写新的消息似乎更接近您的目标,并且仍然允许您使用看起来像豆子的东西。
然而,真正的答案似乎是AutoBean.setTag和getTag方法:
/**
* A tag is an arbitrary piece of external metadata to be associated with the
* wrapped value.
*
* @param tagName the tag name
* @param value the wrapped value
* @see #getTag(String)
*/
void setTag(String tagName, Object value);..。
/**
* Retrieve a tag value that was previously provided to
* {@link #setTag(String, Object)}.
*
* @param tagName the tag name
* @return the tag value
* @see #setTag(String, Object)
*/
<Q> Q getTag(String tagName);从这些方法在AbstractAutoBean中的实现可以看出,这些方法将它们的数据存储在与通过网络发送的数据完全不同的对象中。缺点是,为了调用这些方法,您需要获得底层的AutoBean对象(请参阅com.google.web.bindery.autobean.shared.AutoBeanUtils.getAutoBean(U)了解其中的一种方法)。
发布于 2014-03-01 05:59:02
解码为父接口的子类/接口在解码时不会爆炸,从而允许在编组步骤之前将商品一起传递。我立即对下面的实际代码进行了测试,测试结果与预期一致。
public interface ReplicateOptions {
/**
* Create target database if it does not exist. Only for server replications.
*/
Boolean getCreateTarget();
void setCreateTarget(Boolean create_target);
//baggage to pass along
interface ReplicateCall<T> extends ReplicateOptions {
/**
* If true starts subscribing to future changes in the source database and continue replicating them.
*/
AsyncCallback<T> getContinuous();
void setContinuous(AsyncCallback<T> continuous);
}
}https://stackoverflow.com/questions/13849281
复制相似问题