时间戳格式的时间从json转为date时

配置:

import java.util.Date;

import net.sf.ezmorph.object.AbstractObjectMorpher;
/**
 * 
 * @author chaico
 *
 */
public class TimestampToDateMorpher extends AbstractObjectMorpher {
    

   

    public Object morph(Object value) {
        if( value != null){
            return new Date(Long.parseLong(String.valueOf(value)));
        }     
        return null;
    }

    @Override
    public Class morphsTo() {
        return Date.class;
    }
    
    public boolean supports( Class clazz ){
       return Long.class.isAssignableFrom( clazz );
    }
}

在JSON toBean时调用:

JSONUtils.getMorpherRegistry().registerMorpher(new TimestampToDateMorpher());
            JSONObject jsonObject = JSONObject.fromObject(responseJson);
            JSONObject.toBean(jsonObject, this.getClass());

相关文章:

  • 2022-12-23
  • 2021-05-15
  • 2021-04-03
  • 2021-11-30
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-10
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案