FasterXML / FasterXML/jackson-future-ideas

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

Offen
#60 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Keine Sprachdaten
Sterne
21
Forks
3
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.