-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
82 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cn.qaiu.vx.core.util; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | ||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; | ||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; | ||
import io.vertx.core.json.jackson.DatabindCodec; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* @author <a href="https://qaiu.top">QAIU</a> | ||
* @date 2023/10/14 9:07 | ||
*/ | ||
public class JacksonConfig { | ||
|
||
static { | ||
// 通过该方法对mapper对象进行设置,所有序列化的对象都将按改规则进行系列化 | ||
// Include.Include.ALWAYS 默认 | ||
// Include.NON_DEFAULT 属性为默认值不序列化 | ||
// Include.NON_EMPTY 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量 | ||
// Include.NON_NULL 属性为NULL 不序列化,就是为null的字段不参加序列化 | ||
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
ObjectMapper objectMapper = DatabindCodec.mapper(); | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
JavaTimeModule javaTimeModule = new JavaTimeModule(); | ||
javaTimeModule.addDeserializer(LocalDateTime.class, | ||
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | ||
javaTimeModule.addDeserializer(LocalDate.class, | ||
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); | ||
javaTimeModule.addDeserializer(LocalTime.class, | ||
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); | ||
objectMapper.registerModule(javaTimeModule); | ||
LoggerFactory.getLogger(JacksonConfig.class).info("Global JacksonConfig complete."); | ||
} | ||
|
||
public static void nothing() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ public static void main(String[] args) { | |
} | ||
|
||
/** | ||
* 框架回调方法 | ||
* 初始化数据库/缓存等 | ||
* | ||
* @param jsonObject 配置 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.