0

Writing Android app to interact with already existing .Net API and ran into date serialization problem. I know that .Net Json date format is /Date(timestamp-timezone)/, however even if I format it like this, I still get error: 'There was an error deserializing the object of type ShoutsOut.Entities.MobileUser. DateTime content '\/Date(1469457720840-0000)\/' does not start with '\/Date(' and end with ')\/' as required for JSON.'

Full stack trace:

at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) 
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) 
at System.ServiceModel.Dispatcher.SingleBodyParameterDataContractMessageFormatter.ReadObject(Message message) 
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.DeserializeRequest(Message message, Object[] parameters) 
at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) 
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) 
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) 
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) 

I'm formatting it like this:

public static String toJson(Date date) {
    return "\\/Date(" + date.getTime() + "-0000)\\/";
}

Tried to:

  • Remove timezone
  • Remove / /
  • add ' between the date

Found slightly different format "\"\\/Date("+date.getTime+"-0500)\\/\"", didn't work either

Edgar.A
  • 1,293
  • 3
  • 13
  • 26
  • Can you [edit] your question to share the raw JSON you are trying to deserialize without any added code escaping? – dbc Jul 25 '16 at 15:40
  • `"Expires":"\"\\/Date(1469515755860-0000)\\/\""` I think I can see the problem now, problem is how do I write \/ part without escaping? – Edgar.A Jul 26 '16 at 06:50

1 Answers1

0

This answer solved it for me, basically had to change date data type to DateTime from Joda time library, and implemented custom serializer/deserializer

Community
  • 1
  • 1
Edgar.A
  • 1,293
  • 3
  • 13
  • 26