mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-06-06 13:54:03 +08:00
[update] JsonUtil 升级优化,增加特殊需求String的反序列化
This commit is contained in:
parent
a05bb00123
commit
3ddd11f9c9
@ -0,0 +1,38 @@
|
||||
package com.yexuejc.base.converter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* json中的“”转String对象时值为null
|
||||
* 例子:{str:""} ->
|
||||
* JsonBean{
|
||||
* public String str;
|
||||
* }
|
||||
* str的值为null [不使用{@link StringDeserializer},str的值为“”]
|
||||
* </pre>
|
||||
*
|
||||
* <pre>
|
||||
* 使用方式:
|
||||
* jsonMapper.registerModule(new SimpleModule().addDeserializer(String.class, new StringDeserializer()));
|
||||
* </pre>
|
||||
*
|
||||
* @author yexuejc
|
||||
* @date 2022/10/08
|
||||
*/
|
||||
public class StringDeserializer extends JsonDeserializer<String> {
|
||||
|
||||
@Override
|
||||
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
|
||||
throws IOException {
|
||||
String timeString = jsonParser.getValueAsString();
|
||||
if ("".equals(timeString)) {
|
||||
return null;
|
||||
}
|
||||
return timeString;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user