1.4.4 JsonUtil类修复格式化出现的时区差

This commit is contained in:
yexuejc 2021-04-24 00:52:35 +08:00
parent d602d4370e
commit 5a96c23882
3 changed files with 29 additions and 2 deletions

View File

@ -1,6 +1,12 @@
yexuejc-base 更新记录
------------------
#### version 1.4.4
**time2021-4-24 00:41:31** <br/>
**branch** master <br/>
**update** <br/>
>1. JsonUtil类修复格式化出现的时区差现使用TimeZone.getDefault()时区
#
#### version 1.4.3
**time2021-2-6 11:42:49** <br/>
**branch** master <br/>

View File

@ -6,7 +6,7 @@
<groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
<name>${project.artifactId}</name>
<url>https://github.com/yexuejc/yexuejc-base</url>

View File

@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.type.MapType;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.TimeZone;
import java.util.logging.Logger;
/**
@ -46,6 +47,8 @@ public class JsonUtil {
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//设置一下时区可以和程序同步避免时区问题
objectMapper.setTimeZone(TimeZone.getDefault());
objectMapper.setDateFormat(DateUtil.DATE_TIME_FORMAT);
}
@ -55,6 +58,15 @@ public class JsonUtil {
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
}
/**
* 这个设置不能改变JsonUtil自带的objectMapper设置只能修改传入objMapper的设置
* @param objMapper
*/
public static void initSnakeCase(ObjectMapper objMapper) {
//驼峰下划线互转
objMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
}
/**
* 每调用一次生成一个全新的ObjectMapper供特殊场景使用与通用ObjectMapper没有关系
*
@ -66,6 +78,15 @@ public class JsonUtil {
return objectMapper;
}
/**
* 返回 ObjectMapper对象供外部设置特定参数
*
* @return
*/
public static ObjectMapper getObjectMapper() {
return objectMapper;
}
/**
* 将json转换为某个类
*