私はComponents
のSet
を持っている:Jacksonのシリアル化から1つのコレクション要素を除外する方法は?
final class User{
private final Set<Component> COMPONENTS;
public User(String userID)
{
this.userID = userID;
COMPONENTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
new AuthorizationComponent(this.getUserID())
new ProfileComponent(this.getUserID()),
new ThemeComponent(this.getUserID()))
));
}
}
各コンポーネント:認証、プロファイル、テーマはComponent
のサブクラスです。
は今、私はUser
を作成し、JSON
文字列に変換します
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(user);
私はこのString
からAuthorizationComponent
を除外する必要があります。 transient
修飾子と注釈を使用することができますが、これはフィールドでのみ機能し、コレクション要素を1つだけ削除する必要があります。
これは可能ですか?
は、このリンクはあなたのために参考になりましたか? https://github.com/FasterXML/jackson-annotations/issues/25 – utkusonmez