xmlutil icon indicating copy to clipboard operation
xmlutil copied to clipboard

Exceptions thrown should be SerializationException

Open florianmutter opened this issue 1 year ago • 3 comments

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

florianmutter avatar Jul 18 '24 07:07 florianmutter

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.

pdvrieze avatar Jul 19 '24 09:07 pdvrieze

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.

sschuberth avatar Sep 16 '24 06:09 sschuberth

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

Nevermind, I guess I'm looking for https://github.com/pdvrieze/xmlutil/issues/197.

sschuberth avatar Sep 16 '24 11:09 sschuberth