Skip to content

Commit

Permalink
bugfix jackson deserialize localDatetime error (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Sep 13, 2023
1 parent f067e76 commit 525539b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.dromara.hertzbeat.alert.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.dromara.hertzbeat.alert.reduce.AlarmCommonReduce;
import org.dromara.hertzbeat.alert.dao.AlertDao;
import org.dromara.hertzbeat.alert.dto.AlertPriorityNum;
Expand Down Expand Up @@ -156,15 +155,17 @@ private Alert buildAlertData(AlertReport alertReport){
}else{
sb = new StringBuilder(alertReport.getContent());
}

LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(alertReport.getAlertTime()),
ZoneId.systemDefault());
return Alert.builder()
.content("Alert Center\n" + sb)
.priority(alertReport.getPriority().byteValue())
.status(CommonConstants.ALERT_STATUS_CODE_PENDING)
.tags(alertReport.getLabels())
.target(alertReport.getAlertName())
.triggerTimes(1)
.gmtCreate(LocalDateTime.ofInstant(Instant.ofEpochMilli(alertReport.getAlertTime()), ZoneId.systemDefault()))
.gmtCreate(dateTime)
.gmtUpdate(dateTime)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class AlertReport {
private Integer alertDuration;

@Schema(title = "Time when the log service receives the alarm message", description = "日志服务接收到告警消息的时间",
example = "1648889320", accessMode = READ_WRITE)
example = "1694589491000", accessMode = READ_WRITE)
private long alertTime;

@Schema(title = "Alarm priority. 0: high emergency alarm red 1: medium critical serious alarm Orange 2: low warning warning alarm yellow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

Expand All @@ -41,7 +42,8 @@ public class JsonUtil {
static {
OBJECT_MAPPER
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.registerModule(new JavaTimeModule());
}

public static String toJson(Object source) {
Expand Down

0 comments on commit 525539b

Please sign in to comment.