JSON to Bean Timestamp To Date 타임스탬프 날짜
1055 단어 Json toBean
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());