zoukankan      html  css  js  c++  java
  • @JsonFormat与@DateTimeFormat注解的使用和Timestamp取出来1970问题和@JSONField(name="Timestamp",deserializeUsing= FastJsonLocalDateTimeDeserializer.class)

    总结: 

      注解@JsonFormat主要是后台到前台的时间格式的转换

      注解@DataFormAT主要是前后到后台的时间格式的转换

    @JSONField 是解决
    UserDto dto = JSONObject.parseObject(strJson, UserDto.class); 解决从Json里面取出来的时间戳 为1970的问题
    public class FastJsonLocalDateTimeDeserializer implements ObjectDeserializer {
    
        private static List<DateTimeFormatter> dateTimeFormatters = new LinkedList<>();
    
        static {
            // Add your own formatter to there
            dateTimeFormatters.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            dateTimeFormatters.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
            dateTimeFormatters.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"));
            dateTimeFormatters.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS"));
        }
    
        @SuppressWarnings("unchecked")
        @Override
        public LocalDateTime deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
            final Long input = parser.lexer.longValue();
            LocalDateTime localDateTime = null;
            localDateTime=LocalDateTime.ofEpochSecond(input,0,ZoneOffset.of("+8"));
            Assert.notNull(localDateTime, "FastJson LocalDateTime use" +
                    " FastJsonTimestampDeserializer format error: " + input);
            return localDateTime;
        }
    
        @Override
        public int getFastMatchToken() {
            return JSONToken.LITERAL_INT;
        }
    }
  • 相关阅读:
    dva实用的学习笔记
    上传图片到七牛云
    Lodash学习笔记
    Ant Design Pro 脚手架+umiJS 实践总结
    SVN的安装和使用手册
    判断数据类型的5种方法
    常见react面试题汇总(适合中级前端)
    Es6 类class的关键 super、static、constructor、new.target
    ES2019 新特性简介
    通用正则实战200
  • 原文地址:https://www.cnblogs.com/shanheyongmu/p/13321335.html
Copyright © 2011-2022 走看看