FasterXML / FasterXML/jackson-future-ideas

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

Aperta
#60 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
21
Fork
3
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.