FasterXML / FasterXML/jackson-module-scala
Empty JSON when serializing from Scala class with @JsonFilter annotation
- Lingua principale
- Scala
- Stelle
- 506
- Fork
- 138
- Merge medio
- 3h 6m
- PR unite (30g)
- 48
Descrizione
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 _)
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.