FasterXML / FasterXML/jackson-future-ideas

No way to ignore exception during a field/property serialization and keep trying to serialize the rest properties

Open
#60 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
21
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Dear team, could you please add, or maybe there is already such functionality for ignoring an exception during a calling some property to get its value to serialize. Here is my case my POJO is actually a hibernate proxy and when ObjectMapper reads some of its property there is an SQL Exception, that actually I'd like to ignore and serialize as null rather than get an exception.
I was even trying to add some custom module but it is not working eventually:
```
.registerModule(SimpleModule().setSerializerModifier(object : BeanSerializerModifier() {
override fun changeProperties(config: SerializationConfig, beanDesc: BeanDescription, properties: List) = properties.map {
object : BeanPropertyWriter(it) {
override fun serializeAsField(bean: Any, gen: JsonGenerator, prov: SerializerProvider) = try {
super.serializeAsField(bean, gen, prov)
} catch (exception: Exception) {
println("ignoring $exception for field $name of $bean instance")
}
}
}
}))

```

Please give a piece of advice how to handle such case

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.