Autobeans は、JSON/XML/その他の形式の Java スキンであることを意図しています。実際には、他のデータを保持するようには設計されていません。とはいえ、すぐに使用できるツールを使用して質問にほぼ答えるか、問題を解決する方法に関する他のアイデアを刺激する可能性のあるいくつかの考えがあります。
セッターを省略することで、読み取り専用のプロパティを構築できるはずです。これはあなたが求めているものではありませんが、それでも便利かもしれません。
これらの線に沿って、@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
andgetTag
メソッドのようです。
/**
* 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)
これを行う 1 つの方法については、を参照してください)。