forked from alibaba/fastjson
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alibaba#941 from wuwen5/fixed#849#937
Fixed#849#937
- Loading branch information
Showing
3 changed files
with
98 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/com/alibaba/json/bvt/TypeReferenceTest12.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.alibaba.json.bvt; | ||
|
||
import com.alibaba.fastjson.TypeReference; | ||
import junit.framework.TestCase; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Created by wuwen on 2016/12/7. | ||
*/ | ||
public class TypeReferenceTest12 extends TestCase { | ||
|
||
public void test_same() throws Exception { | ||
ParameterizedType type1 = getType(Integer.class); | ||
ParameterizedType type2 = getType(); | ||
|
||
assertEquals(type1.getRawType(), type2.getRawType()); | ||
assertSame(type1.getRawType(), type2.getRawType()); | ||
} | ||
|
||
<T> ParameterizedType getType(Type type) { | ||
return (ParameterizedType)new TypeReference<Model<T>>(type) {}.getType(); | ||
} | ||
|
||
ParameterizedType getType() { | ||
return (ParameterizedType)new TypeReference<Model<Integer>>() {}.getType(); | ||
} | ||
|
||
public static class Model<T> { | ||
public T value; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_937.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.TypeReference; | ||
import junit.framework.TestCase; | ||
import org.junit.Assert; | ||
|
||
/** | ||
* Created by wuwen on 2016/12/7. | ||
*/ | ||
public class Bug_for_issue_937 extends TestCase { | ||
|
||
public void test_for_issue() throws Exception { | ||
String json = "{outPara:{name:\"user\"}}"; | ||
Out<Info> out = returnOut(json, Info.class); | ||
Assert.assertEquals("user", out.getOutPara().getName()); | ||
} | ||
|
||
public static <T> Out<T> returnOut(String jsonStr, Class<T> c2) { | ||
return JSON.parseObject(jsonStr, new TypeReference<Out<T>>(c2) { | ||
}); | ||
} | ||
|
||
public static class Out<T> { | ||
private T outPara; | ||
|
||
public void setOutPara(T t) { | ||
outPara = t; | ||
} | ||
|
||
public T getOutPara() { | ||
return outPara; | ||
} | ||
|
||
public Out() { | ||
} | ||
|
||
public Out(T t) { | ||
setOutPara(t); | ||
} | ||
} | ||
|
||
public static class Info { | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |