org.shoulder.web.template.dictionary.convert.DictionaryItemDTODeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shoulder-web Show documentation
Show all versions of shoulder-web Show documentation
shoulder WEB 模块,基于Spring Boot Web提供了 Controller AOP 日志、AOP异常处理,统一返回值,健康检查,租户、用户解析,Web
安全防护,通用CrudController,动态字典,标签管理,HTTP client AOP日志、AOP异常处理等能力,助力Web飞速开发。
The newest version!
package org.shoulder.web.template.dictionary.convert;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.shoulder.core.dictionary.model.DictionaryItemEnum;
import org.shoulder.core.util.ConvertUtil;
import org.shoulder.web.template.dictionary.dto.DictionaryItemDTO;
import java.io.IOException;
/**
* 支持前端传 String,后端用 DictionaryItemDTO 接收
*
* @author lym
*/
public abstract class DictionaryItemDTODeserializer extends JsonDeserializer {
/**
* 实际枚举字典类型
*/
protected final Class extends DictionaryItemEnum> dictionaryClass;
public DictionaryItemDTODeserializer(Class extends DictionaryItemEnum> dictionaryClass) {
this.dictionaryClass = dictionaryClass;
}
@Override
public DictionaryItemDTO deserialize(JsonParser p, DeserializationContext context) throws IOException {
String text = p.getText();
if (text == null || text.isEmpty()) {
return null;
}
// if (!text.startsWith("{") && text.endsWith("}")) {
DictionaryItemEnum dictionaryItemEnum = ConvertUtil.convert(text, dictionaryClass);
return ConvertUtil.convert(dictionaryItemEnum, DictionaryItemDTO.class);
// }
// todo 直接转化
// return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy