FasterXML / FasterXML/jackson-module-scala

Empty JSON when serializing from Scala class with @JsonFilter annotation

Open
#217 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
506
Forks
138
Avg merge
3h 6m
Merged PRs (30d)
48

Description

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 _)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.