Skip to content

Commit

Permalink
fix: missing matching Hashtable for alibaba#1707
Browse files Browse the repository at this point in the history
Signed-off-by: Kraity <kraty@krait.cn>
  • Loading branch information
kraity committed Aug 6, 2023
1 parent 11fbf56 commit 84115c6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,6 @@ public ObjectReader getObjectReader(ObjectReaderProvider provider, Type type) {
case "org.springframework.security.web.authentication.WebAuthenticationDetails":
internalMixin = "org.springframework.security.web.jackson2.WebAuthenticationDetailsMixin";
break;
default:
break;
}

if (internalMixin != null) {
Expand Down Expand Up @@ -1950,12 +1948,14 @@ public ObjectReader getObjectReader(ObjectReaderProvider provider, Type type) {
return typedMap((Class) rawType, ConcurrentSkipListMap.class, actualTypeParam0, actualTypeParam1);
}

if (rawType == LinkedHashMap.class || rawType == TreeMap.class) {
if (rawType == LinkedHashMap.class
|| rawType == TreeMap.class
|| rawType == Hashtable.class) {
return typedMap((Class) rawType, (Class) rawType, actualTypeParam0, actualTypeParam1);
}

if (rawType == Map.Entry.class) {
return new ObjectReaderImplMapEntry(actualTypeArguments[0], actualTypeArguments[1]);
return new ObjectReaderImplMapEntry(actualTypeParam0, actualTypeParam1);
}

switch (rawType.getTypeName()) {
Expand All @@ -1969,12 +1969,8 @@ public ObjectReader getObjectReader(ObjectReaderProvider provider, Type type) {
case "org.apache.commons.lang3.tuple.Pair":
case "org.apache.commons.lang3.tuple.ImmutablePair":
return new ApacheLang3Support.PairReader((Class) rawType, actualTypeParam0, actualTypeParam1);
default:
break;
}
}

if (actualTypeArguments.length == 1) {
} else if (actualTypeArguments.length == 1) {
Type itemType = actualTypeArguments[0];
Class itemClass = TypeUtils.getMapping(itemType);

Expand Down Expand Up @@ -2048,8 +2044,6 @@ public ObjectReader getObjectReader(ObjectReaderProvider provider, Type type) {
case "com.google.common.collect.ImmutableSet":
case "com.google.common.collect.SingletonImmutableSet":
return ObjectReaderImplList.of(type, null, 0);
default:
break;
}

if (rawType == Optional.class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.alibaba.fastjson2.issues_1700;

import com.alibaba.fastjson2.JSON;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* @author kraity
*/
public class Issue1707 {
@Test
public void test0() {
String text = "{\"order\":{\"column\":\"post_sort\",\"sequences\":\"asc\"}}";
TestModule test = JSON.parseObject(text, TestModule.class);

assertNotNull(test);
assertNotNull(test.order);
assertEquals(2, test.order.size());
assertEquals("asc", test.order.get("sequences"));
}

@Test
public void test1() {
String text = "{\"dictKey\":\"sys_post\",\"tableName\":\"sys_post\",\"queryColumns\":{\"code\":\"post_id\",\"sort\":\"post_sort\",\"label\":\"post_name\",\"value\":\"post_id\"},\"params\":{\"orCondition\":[{\"column\":\"status\",\"operator\":\"<>\",\"value\":1},{\"column\":\"status\",\"operator\":\"is\",\"value\":null}]},\"orders\":[{\"column\":\"post_sort\",\"sequences\":\"asc\"},{\"column\":\"create_time\",\"sequences\":\"desc\"}]}";
DictionaryModule dic = JSON.parseObject(text, DictionaryModule.class);

assertNotNull(dic);
assertNotNull(dic.orders);
assertEquals(2, dic.orders.size());
assertEquals(2, dic.orders.get(0).size());
assertEquals(2, dic.orders.get(1).size());
assertEquals("desc", dic.orders.get(1).get("sequences"));
}

@Getter
@Setter
public static class TestModule
implements Serializable {
private static final long serialVersionUID = -1L;
private Hashtable<String, String> order;
}

@Getter
@Setter
public static class DictionaryModule
implements Serializable {
private static final long serialVersionUID = -1L;
private String dictKey;
private String tableName;
private Hashtable<String, String> queryColumns;
private Hashtable<String, List<HashMap<String, Object>>> params;
private List<Hashtable<String, String>> orders;
}
}

0 comments on commit 84115c6

Please sign in to comment.