mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix ser bug
This commit is contained in:
parent
3b0201c864
commit
17d259a309
@ -2,8 +2,10 @@ package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 驼峰Key风格的Map<br>
|
||||
@ -73,7 +75,8 @@ public class CamelCaseMap<K, V> extends FuncKeyMap<K, V> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
CamelCaseMap(final MapBuilder<K, V> emptyMapBuilder) {
|
||||
super(emptyMapBuilder.build(), (key) -> {
|
||||
// issue#I5VRHW@Gitee 使Function可以被序列化
|
||||
super(emptyMapBuilder.build(), (Function<Object, K> & Serializable)(key) -> {
|
||||
if (key instanceof CharSequence) {
|
||||
key = StrUtil.toCamelCase(key.toString());
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 忽略大小写的Map<br>
|
||||
@ -73,7 +75,8 @@ public class CaseInsensitiveMap<K, V> extends FuncKeyMap<K, V> {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
CaseInsensitiveMap(final MapBuilder<K, V> emptyMapBuilder) {
|
||||
super(emptyMapBuilder.build(), (key)->{
|
||||
// issue#I5VRHW@Gitee 使Function可以被序列化
|
||||
super(emptyMapBuilder.build(), (Function<Object, K> & Serializable)(key)->{
|
||||
if (key instanceof CharSequence) {
|
||||
key = key.toString().toLowerCase();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.io.SerializeUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -20,4 +21,16 @@ public class CamelCaseMapTest {
|
||||
Assert.assertEquals("OK", map.get("customKey"));
|
||||
Assert.assertEquals("OK", map.get("custom_key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializableKeyFuncTest() {
|
||||
final CamelCaseMap<String, String> map = new CamelCaseMap<>();
|
||||
map.put("serializable_key", "OK");
|
||||
final CamelCaseMap<String, String> deSerializableMap = SerializeUtil.deserialize(SerializeUtil.serialize(map));
|
||||
Assert.assertEquals("OK", deSerializableMap.get("serializable_key"));
|
||||
Assert.assertEquals("OK", deSerializableMap.get("serializableKey"));
|
||||
deSerializableMap.put("serializable_func", "OK");
|
||||
Assert.assertEquals("OK", deSerializableMap.get("serializable_func"));
|
||||
Assert.assertEquals("OK", deSerializableMap.get("serializableFunc"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user