您可以创建自定义解串器
public class CustomJsonTimeDeserializerWithoutTimeZone extends JsonDeserializer<Time>{ @Override public Time deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { DateFormat format = new SimpleDateFormat("hh:mm:ss.SSS"); Time time = null; try{ Date dt = format.parse("10:30:00.000-05.00".substring(0,12)); // remove incorrect timezone format return new Time(dt.getTime()); }catch (ParseException e){ e.printStackTrace(); } }}
告诉杰克逊使用您的自定义解串器
public class Model{ @JsonDeserialize(using = CustomJsonTimeDeserializerWithoutTimeZone.class) private Time time;}
并像这样使用它:
ObjectMapper mapper = new ObjectMapper();String jsonString = ...// jsonString retrieve from external serviceModel model = mapper.readValue(jsonString, Model.class);
您可以使用Jackson自定义序列化为服务响应添加时区信息
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)