FasterXML / FasterXML/jackson-module-scala

Empty JSON when serializing from Scala class with @JsonFilter annotation

オープン
#217 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Scala
スター
506
フォーク
138
平均マージ
3時間 6分
マージ済み PR(30日)
48

説明

Does this module support using @JsonFilter within a Scala class to filter out attributes? When I add it to a getter on my Scala class, the resulting object in the JSON is empty: `{}`.

I'm using an ObjectMapper like this to try and serialize a `Product` Java object. @JsonFilter is necessary to filter out instances where `Product` or stuff that's related to it references itself.

``` java
private static final ObjectMapper JSON_MAPPER = new ObjectMapper()
.registerModule(new DefaultScalaModule());

private static final FilterProvider JSON_SERIALIZATION_FILTERS = new SimpleFilterProvider()
.addFilter(
"addOnProduct",
SimpleBeanPropertyFilter.filterOutAllExcept(Sets.newHashSet("id", "price"))
);

...

JSON_MAPPER.writer(JSON_SERIALIZATION_FILTERS).writeValue(response.getOutputStream(), product);
```

Product.java has
`Trim getTrim()`

Trim.scala has a Trim case class with this:

``` scala
@JsonFilter("addOnProduct")
def product: Option[Product] = productCode map(Product.of _)
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。