pdvrieze / xmlutil

XML Serialization library for Kotlin

Home Page:https://pdvrieze.github.io/xmlutil/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exceptions thrown should be SerializationException

florianmutter opened this issue · comments

To make it easier to handle issues when serialization or de-serialization xmlutil should throw exceptions that inherits from kotlinx.serialization.SerializationException

I can have a look at that for exceptions in the serializer code/module itself (I believe those are already inheriting SerializationException), but parsing is an independent module that throws its own exceptions. There can also be exceptions thrown by the (de)serialized classes.
A separate issue is compatibility with existing code, and adding a superclass would be a potentially breaking change.

Would implementing this solve the issue of exceptions not listing the affected field? I'm currently getting something like

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:672)
	at java.base/java.lang.Integer.parseInt(Integer.java:778)
	at nl.adaptivity.xmlutil.serialization.XmlDecoderBase$DecodeCommons.decodeInt(XMLDecoder.kt:112)
	at kotlinx.serialization.internal.IntSerializer.deserialize(Primitives.kt:125)
	at kotlinx.serialization.internal.IntSerializer.deserialize(Primitives.kt:121)
	at nl.adaptivity.xmlutil.serialization.XmlDecoderBase$TagDecoderBase.decodeNullableSerializableElement(XMLDecoder.kt:906)

with no indication which Int-field cannot be deserialized as its input contains an empty string.

Would implementing this solve the issue of exceptions not listing the affected field?

Nevermind, I guess I'm looking for #197.