I'm considering passing xml back and forth for error messages but each error has different scenarios.
one situation at hand is passing diffed text comparison while others are as simple as passing a text message.
What kind of serialization/deserialization strategy could I use for such a scenario?
The main issue with a scenario like this is that the object is different from case to case and there needs to be a mechanism for identifying what type it is.
Serializing xml is pretty straight forward:
Three sloppy ideas pop into my mind from the start:
- Make some super class that contains every possibility of contained types.
- Make some mechanism for reading the xml first to identify what's in it.
- Use option 2 and convert the inner body xml to an object.
A more elegant approach would be to implement some kind of Action pattern, where, once the object was identified you could create the proper action to take with it.
Some ideas consist of the Action/Executor pattern or IoC:
Here is an example pattern idea that runs parrallel to what I'm thinking:
Not for data persistence but for error handling by the client: The client decides how to handle the error once received based on the Action from a base library that takes place after deserialization.
my considered xml format would be something like this:
<errorMessage> <header>The header is not correct</header> <body> <diffErrorArray> <diffItem message="NoChange"> <customMessage>Correct</customMessage> <source>HeaderColumn1</source> <destination>HeaderColumn1</destination> </diffItem> <diffItem message="Replace"> <customMessage>Changed</customMessage> <source>HeaderColumn1</source> <destination>Header_Column_1</destination> </diffItem> <diffItem message="AddDestination"> <customMessage>Unknown</customMessage> <source></source> <destination>Header_Column_1</destination> </diffItem> <diffItem message="DeleteSource"> <customMessage>Missing</customMessage> <source>HeaderColumn2</source> <destination></destination> </diffItem> </diffErrorArray> </body> </errorMessage>
<errorMessage> <header>Bad news</header> <body> <stringErrorMessage>Something really bad happened.</stringErrorMessage> <body> </errorMessage>