-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from hocgin/v1.0.39
[新增功能](v1.0.39): 处理 long 类型在前端可能出现问题
- Loading branch information
Showing
3 changed files
with
66 additions
and
7 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
29 changes: 29 additions & 0 deletions
29
...gure/src/main/java/in/hocg/boot/web/autoconfiguration/jackson/xlong/LongDeserializer.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,29 @@ | ||
package in.hocg.boot.web.autoconfiguration.jackson.xlong; | ||
|
||
import cn.hutool.core.convert.Convert; | ||
import cn.hutool.core.util.StrUtil; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Created by hocgin on 2019/5/22. | ||
* email: hocgin@gmail.com | ||
* | ||
* @author hocgin | ||
*/ | ||
public class LongDeserializer extends JsonDeserializer<Long> { | ||
@Override | ||
public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
if (Objects.nonNull(p)) { | ||
return Convert.toLong(p.getText()); | ||
} | ||
return null; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...figure/src/main/java/in/hocg/boot/web/autoconfiguration/jackson/xlong/LongSerializer.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,29 @@ | ||
package in.hocg.boot.web.autoconfiguration.jackson.xlong; | ||
|
||
import cn.hutool.core.util.ObjectUtil; | ||
import cn.hutool.core.util.StrUtil; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
/** | ||
* Created by hocgin on 2019/5/22. | ||
* email: hocgin@gmail.com | ||
* | ||
* @author hocgin | ||
*/ | ||
public class LongSerializer extends JsonSerializer<Long> { | ||
@Override | ||
public void serialize(Long val, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | ||
if (ObjectUtil.isNull(val)) { | ||
jsonGenerator.writeNull(); | ||
} else { | ||
jsonGenerator.writeString(val.toString()); | ||
} | ||
} | ||
} |