2

UIにのみ必要なプロパティを持つautobeanがあります。値をnullにすることができ、AutoBeanCodexそのプロパティはシリアル化されないと思いますが、これはシリアル化で必要な追加の手順に相当します。

注釈に似た注釈を期待していましたEditor @Ignore。例えば:

public interface Foo {
    ...
    @Ignore
    String getUiOnlyProperty();
}

それで、シリアル化時に値をヌルにする以外に、autobeanプロパティがシリアル化されないようにする他の方法はありますか?

4

2 に答える 2

2

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.setTagandgetTagメソッドのようです。

/**
 * 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 つの方法については、を参照してください)。

于 2012-12-12T22:52:06.983 に答える
0

親インターフェイスとしてデコードされた子クラス/インターフェイスは、デコード時に爆発せず、マーシャリング手順の前に商品を一緒に渡すことができます。以下の実際のコードの即時テストは、期待どおりに実行されています。

  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); 

}
}
于 2014-02-28T21:59:02.300 に答える