[英]How to serialize/deserialize an ASP.NET JSON date using Jackson?
I'm having some difficulty trying to get Jackson to serialize/deserialize JSON date strings sent from an ASP.NET service. 我在尝试让Jackson序列化/反序列化从ASP.NET服务发送的JSON日期字符串时遇到一些困难。 The string is in the following format:
字符串格式如下:
/Date(1234567890123)/
A simple example of the type of output I get from the server is like the following: 我从服务器获取的输出类型的一个简单示例如下:
{
"name" : "Bob Marley",
"birthdate" : "/Date(1234567890123)/"
}
How can I get Jackson to convert the date to a Java date object? 如何获得Jackson将日期转换为Java日期对象? Is there a way to do it without having to write a custom serializer/deserializer?
有没有一种方法可以不必编写自定义的序列化器/反序列化器?
Your best bet is to write a custom deserializer. 最好的选择是编写一个自定义解串器。 Or alternatively, to store the string representation of the date in your bean, but provide an alternative getter that converts the string to a date using a DateFormat instance.
或者,将日期的字符串表示形式存储在bean中,但提供一个替代的getter方法,该方法使用DateFormat实例将字符串转换为日期。 The first option is cleaner and more efficient.
第一种选择是更清洁,更高效。
I think the ASP.NET service is producing a strange value for the date and would change that if I could. 我认为ASP.NET服务为该日期生成了一个奇怪的值,如果可以的话,它将改变它。 If I cannot, then writing a customer deserializer is the way to go.
如果我做不到,那么写一个客户反序列化器就是路要走。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.