mirror of
https://github.com/dromara/tianai-captcha.git
synced 2026-05-07 06:04:34 +08:00
处理 ResourceMap.java json序列化异常
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cloud.tianai.captcha</groupId>
|
||||
<artifactId>tianai-captcha</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<version>1.4.2</version>
|
||||
|
||||
<name>tianai-captcha</name>
|
||||
<description>行为验证码</description>
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class AbstractImageCaptchaGenerator implements ImageCaptchaGener
|
||||
|
||||
protected ResourceMap requiredRandomGetTemplate(String type, String tag) {
|
||||
ResourceMap templateMap = imageCaptchaResourceManager.randomGetTemplate(type, tag);
|
||||
if (CollectionUtils.isEmpty(templateMap)) {
|
||||
if (templateMap == null || CollectionUtils.isEmpty(templateMap.getResourceMap())) {
|
||||
throw new ImageCaptchaException("随机获取模板资源失败, 获取到的资源为空, type=" + type + ",tag=" + tag);
|
||||
}
|
||||
return templateMap;
|
||||
@@ -137,7 +137,7 @@ public abstract class AbstractImageCaptchaGenerator implements ImageCaptchaGener
|
||||
}
|
||||
|
||||
|
||||
protected InputStream getTemplateFile(Map<String, Resource> templateImages, String imageName) {
|
||||
protected InputStream getTemplateFile(ResourceMap templateImages, String imageName) {
|
||||
Resource resource = templateImages.get(imageName);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("查找模板异常, 该模板下未找到 ".concat(imageName));
|
||||
@@ -145,7 +145,7 @@ public abstract class AbstractImageCaptchaGenerator implements ImageCaptchaGener
|
||||
return getResourceInputStream(resource, null);
|
||||
}
|
||||
|
||||
protected BufferedImage getTemplateImage(Map<String, Resource> templateImages, String imageName) {
|
||||
protected BufferedImage getTemplateImage(ResourceMap templateImages, String imageName) {
|
||||
InputStream stream = getTemplateFile(templateImages, imageName);
|
||||
BufferedImage bufferedImage = CaptchaImageUtils.wrapFile2BufferedImage(stream);
|
||||
closeStream(stream);
|
||||
@@ -190,7 +190,7 @@ public abstract class AbstractImageCaptchaGenerator implements ImageCaptchaGener
|
||||
return stream;
|
||||
}
|
||||
|
||||
protected Optional<BufferedImage> getTemplateImageOfOptional(Map<String, Resource> templateImages, String imageName) {
|
||||
protected Optional<BufferedImage> getTemplateImageOfOptional(ResourceMap templateImages, String imageName) {
|
||||
Optional<InputStream> optional = getTemplateFileOfOptional(templateImages, imageName);
|
||||
if (optional.isPresent()) {
|
||||
InputStream inputStream = optional.get();
|
||||
@@ -201,7 +201,7 @@ public abstract class AbstractImageCaptchaGenerator implements ImageCaptchaGener
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
protected Optional<InputStream> getTemplateFileOfOptional(Map<String, Resource> templateImages, String imageName) {
|
||||
protected Optional<InputStream> getTemplateFileOfOptional(ResourceMap templateImages, String imageName) {
|
||||
Resource resource = templateImages.get(imageName);
|
||||
if (resource == null) {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cloud.tianai.captcha.resource.common.model.dto;
|
||||
|
||||
import cloud.tianai.captcha.resource.common.model.dto.Resource;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: 天爱有情
|
||||
@@ -12,24 +12,47 @@ import java.util.HashMap;
|
||||
* @Description 存储一组Resource的Map, 增加tag标记
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ResourceMap extends HashMap<String, Resource> {
|
||||
@EqualsAndHashCode
|
||||
public class ResourceMap {
|
||||
|
||||
private Map<String, Resource> resourceMap;
|
||||
private String tag;
|
||||
|
||||
public ResourceMap(String tag) {
|
||||
this.tag = tag;
|
||||
this.resourceMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public ResourceMap(String tag, int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
this.tag = tag;
|
||||
this.resourceMap = new HashMap<>(initialCapacity);
|
||||
}
|
||||
|
||||
public ResourceMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
this.resourceMap = new HashMap<>(initialCapacity);
|
||||
}
|
||||
|
||||
public ResourceMap() {
|
||||
}
|
||||
|
||||
private Map<String, Resource> getResourceMapOfCreate() {
|
||||
if (resourceMap == null) {
|
||||
resourceMap = new HashMap<>(2);
|
||||
}
|
||||
return resourceMap;
|
||||
}
|
||||
|
||||
// ================== Map ==================
|
||||
|
||||
public Resource put(String key, Resource value) {
|
||||
return getResourceMapOfCreate().put(key, value);
|
||||
}
|
||||
|
||||
public Resource get(Object key) {
|
||||
return getResourceMapOfCreate().get(key);
|
||||
}
|
||||
public Resource remove(Object key) {
|
||||
return getResourceMapOfCreate().remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user