ObjectMapper ,XStream 日期格式设置

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.codehaus.jackson.map.ObjectMapper;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class TestController{

    private static ObjectMapper jsonMapper ;  
    private static XStream xmlMapper ;
    
    
    public TestController(){
        jsonMapper = new ObjectMapper(); 
      //反序列化日期格式
        jsonMapper.getDeserializationConfig().setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
      //序列化日期格式
        jsonMapper.getSerializationConfig().setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        
        xmlMapper = new XStream(new DomDriver("utf8"));
        xmlMapper.registerConverter(new DateConverter("yyyy-MM-dd HH:mm:ss", null,
            TimeZone.getTimeZone("GMT+8")));  
    }


}

你可能感兴趣的:(java,ObjectMapper,XStream)