Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
bug fixed for Comparable deserialize, for issue #1834
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 4, 2018
1 parent 9906aad commit c214607
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alibaba.fastjson.parser.deserializer;

import java.io.Closeable;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
Expand Down Expand Up @@ -38,7 +39,12 @@ public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {

}

if (type instanceof Class && type != Object.class && type != Serializable.class) {
if (type instanceof Class
&& type != Object.class
&& type != Serializable.class
&& type != Cloneable.class
&& type != Closeable.class
&& type != Comparable.class) {
return (T) parser.parseObject(type);
}

Expand Down
65 changes: 65 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1800/Issue1834.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.alibaba.json.bvt.issue_1800;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import junit.framework.TestCase;

import java.util.Arrays;
import java.util.List;

public class Issue1834 extends TestCase {
public void test_for_issue() throws Exception {
IndexQuery_Number query_number = new IndexQuery_Number();
IndexQuery_Comparable query_comparable = new IndexQuery_Comparable();
List<Integer> keys = Arrays.asList(1234);
query_number.setKeys(keys);
query_comparable.setKeys(keys);

String json1 = JSON.toJSONString(query_number);
System.out.println(json1);
IndexQuery_Number queryNumber = JSON.parseObject(json1, new TypeReference<IndexQuery_Number>(){});

String json2 = JSON.toJSONString(query_comparable);
System.out.println(json2);
IndexQuery_Comparable queryComparable = JSON.parseObject(json2, new TypeReference<IndexQuery_Comparable>(){});
}

static class IndexQuery_Comparable{
List<? extends Comparable> keys;

public List<? extends Comparable> getKeys() {
return keys;
}

public void setKeys(List<? extends Comparable> keys) {
this.keys = keys;
}

@Override
public String toString() {
return "IndexQuery{" +
"keys=" + keys +
'}';
}
}

static class IndexQuery_Number{
List<? extends Number> keys;

public List<? extends Number> getKeys() {
return keys;
}

public void setKeys(List<? extends Number> keys) {
this.keys = keys;
}

@Override
public String toString() {
return "IndexQuery{" +
"keys=" + keys +
'}';
}
}

}

0 comments on commit c214607

Please sign in to comment.