mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-07 14:24:03 +08:00
1.4.4 JsonUtil类修复格式化出现的时区差
This commit is contained in:
parent
d602d4370e
commit
5a96c23882
@ -1,6 +1,12 @@
|
|||||||
yexuejc-base 更新记录
|
yexuejc-base 更新记录
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
#### version :1.4.4
|
||||||
|
**time:2021-4-24 00:41:31** <br/>
|
||||||
|
**branch:** master <br/>
|
||||||
|
**update:** <br/>
|
||||||
|
>1. JsonUtil类修复格式化出现的时区差:现使用TimeZone.getDefault()时区
|
||||||
|
#
|
||||||
#### version :1.4.3
|
#### version :1.4.3
|
||||||
**time:2021-2-6 11:42:49** <br/>
|
**time:2021-2-6 11:42:49** <br/>
|
||||||
**branch:** master <br/>
|
**branch:** master <br/>
|
||||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>top.yexuejc</groupId>
|
<groupId>top.yexuejc</groupId>
|
||||||
<artifactId>yexuejc-base</artifactId>
|
<artifactId>yexuejc-base</artifactId>
|
||||||
<version>1.4.3</version>
|
<version>1.4.4</version>
|
||||||
|
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<url>https://github.com/yexuejc/yexuejc-base</url>
|
<url>https://github.com/yexuejc/yexuejc-base</url>
|
||||||
|
@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.type.MapType;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +47,8 @@ public class JsonUtil {
|
|||||||
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||||
|
//设置一下时区,可以和程序同步避免时区问题
|
||||||
|
objectMapper.setTimeZone(TimeZone.getDefault());
|
||||||
objectMapper.setDateFormat(DateUtil.DATE_TIME_FORMAT);
|
objectMapper.setDateFormat(DateUtil.DATE_TIME_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +58,15 @@ public class JsonUtil {
|
|||||||
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个设置不能改变JsonUtil自带的objectMapper设置,只能修改传入objMapper的设置
|
||||||
|
* @param objMapper
|
||||||
|
*/
|
||||||
|
public static void initSnakeCase(ObjectMapper objMapper) {
|
||||||
|
//驼峰下划线互转
|
||||||
|
objMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每调用一次生成一个全新的ObjectMapper供特殊场景使用,与通用ObjectMapper没有关系
|
* 每调用一次生成一个全新的ObjectMapper供特殊场景使用,与通用ObjectMapper没有关系
|
||||||
*
|
*
|
||||||
@ -66,6 +78,15 @@ public class JsonUtil {
|
|||||||
return objectMapper;
|
return objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回 ObjectMapper对象,供外部设置特定参数
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ObjectMapper getObjectMapper() {
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将json转换为某个类
|
* 将json转换为某个类
|
||||||
*
|
*
|
||||||
@ -106,7 +127,7 @@ public class JsonUtil {
|
|||||||
log.warning("json to Object JsonMappingException.\n" + e.getMessage());
|
log.warning("json to Object JsonMappingException.\n" + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warning("json to Object IOException.\n" + e.getMessage());
|
log.warning("json to Object IOException.\n" + e.getMessage());
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user