Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Yukooo opened this issue Jun 18, 2021 · 1 comment

Comments

@Yukooo
Copy link

Yukooo commented Jun 18, 2021

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<BeanPropertyWriter>) = 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

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson Jul 2, 2021
@cowtowncoder
Copy link
Member

(moved to here; jackson-databind would be the repo for issue if work was planned)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants