Back Forum Reply New

json deserialization exeption handling

Hi,

I'm a little stuck here as I don't know where to start searching for the solution.

Here is the case. I'm using json for form submittion. For enetity resolution I use JSONDeserializators. Let say I send a date in the wrong format and my deserializator throws an exception.

As this happens before controller I don't know how to send back to form a json encoded error message.

An excerpt from the code (deserializator)HP Code:
packagenbsp;com.objectverse.core.util.json;importnbsp;java.text.SimpleDateFormat;importnbsp;java.util.Date;importnbsp;org.codehaus.jackson.JsonParser;importnbsp;org.codehaus.jackson.map.DeserializationContext;importnbsp;org.codehaus.jackson.map.JsonDeserializer;publicnbsp;classnbsp;JsonDateDeserializernbsp;extendsnbsp;JsonDeserializerlt;Dategt;{nbsp;SimpleDateFormatnbsp;formatternbsp;=nbsp;newnbsp;SimpleDateFormat("dd.MM.yyyy");@Overridenbsp;publicnbsp;Datenbsp;deserialize(JsonParsernbsp;jp,nbsp;DeserializationContextnbsp;ctxt)nbsp;{nbsp;trynbsp;{nbsp;returnnbsp;formatter.parse(jp.getText());}nbsp;catchnbsp;(Exceptionnbsp;e)nbsp;{nbsp;thrownbsp;newnbsp;RuntimeException(e);}nbsp;}}nbsp;

I would need to send back to server JSON encoded error message.

Any help appreciated.

Best regards,Bojan
¥
Back Forum Reply New