kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

MissingFieldException should return class serialName

Open nicktelford opened this issue 9 months ago • 1 comments

MissingFieldException currently provides the names of the missingFields, but it does not provide the name of the class/type the fields were missing from, despite being a constructor parameter.

Currently, the serialName of the affected type is provided to the constructor, and used to construct the error message. This should be made available as a field on the MissingFieldException, to enable programmatic determination of the source of the error.

This is particularly useful when deserializing into a class hierarchy, as the name of the missing field alone may be ambiguous, and exception handlers may need to know the type of the affected class to determine the best course of action.

Adding the serialName as a field should be a trivial addition, since it's already available in the constructor.

It might also be useful to go further, and provide a "path" to the missing fields in the JSON AST, which would provide exception handlers with even more information, which could be especially useful in error messages.

nicktelford avatar Mar 20 '25 19:03 nicktelford

Great idea. This can be done as part of #2464

sandwwraith avatar Mar 26 '25 17:03 sandwwraith