-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
7 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
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
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
20 changes: 20 additions & 0 deletions
20
src/test/java/com/alibaba/json/bvt/fullSer/ToJavaObjectTest.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,20 @@ | ||
package com.alibaba.json.bvt.fullSer; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Created by wenshao on 04/02/2017. | ||
*/ | ||
public class ToJavaObjectTest extends TestCase { | ||
public void test_for_toJavaObject() throws Exception { | ||
JSONObject obj = JSON.parseObject("{\"id\":123}"); | ||
Model model = obj.toJavaObject(Model.class); | ||
assertEquals(123, model.id); | ||
} | ||
|
||
public static class Model { | ||
public int id; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/alibaba/json/bvt/parser/deser/deny/DenyTest16.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,28 @@ | ||
package com.alibaba.json.bvt.parser.deser.deny; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.util.TypeUtils; | ||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Created by wenshao on 29/01/2017. | ||
*/ | ||
public class DenyTest16 extends TestCase { | ||
public void test_deny() throws Exception { | ||
JSONObject object = new JSONObject(); | ||
object.put("@type", "com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase"); | ||
|
||
Throwable error = null; | ||
try { | ||
TypeUtils.castToJavaBean(object, Object.class); | ||
} catch (Exception ex) { | ||
error = ex; | ||
} | ||
assertNotNull(error); | ||
} | ||
|
||
public static class Model { | ||
public Throwable value; | ||
} | ||
} |
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
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,52 @@ | ||
package com.alibaba.json.test.a; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import junit.framework.TestCase; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* Created by wenshao on 04/02/2017. | ||
*/ | ||
public class CompilerTest extends TestCase { | ||
public void test_for_compiler() throws Exception { | ||
byte[] bytes; | ||
{ | ||
Model model = new Model(); | ||
model.id = 123; | ||
|
||
bytes = toBytes(model); | ||
} | ||
|
||
perf(bytes); | ||
for (int i = 0; i < 10; ++i) { | ||
long start = System.currentTimeMillis(); | ||
perf(bytes); | ||
long millis = System.currentTimeMillis() - start; | ||
System.out.println("millis : " + millis); | ||
} | ||
} | ||
|
||
private void perf(byte[] bytes) throws IOException, ClassNotFoundException { | ||
for (int i = 0; i < 1000; ++i) { | ||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes)); | ||
Model model = (Model) in.readObject(); | ||
assertEquals(123, model.id); | ||
} | ||
} | ||
|
||
private byte[] toBytes(Model model) throws IOException { | ||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); | ||
ObjectOutputStream out = new ObjectOutputStream(byteOut); | ||
|
||
out.writeObject(model); | ||
out.flush(); | ||
byte[] bytes = byteOut.toByteArray(); | ||
out.close(); | ||
return bytes; | ||
} | ||
|
||
public static class Model implements Serializable { | ||
public int id; | ||
} | ||
} |
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,24 @@ | ||
package com.alibaba.json.test.a; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.gson.Gson; | ||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Created by wenshao on 04/02/2017. | ||
*/ | ||
public class GsonTest extends TestCase { | ||
public void test_0() throws Exception { | ||
String text = "{\"loader\":\"com.sun.org.apache.bcel.internal.util.ClassLoader\"}"; | ||
|
||
// Gson gson = new Gson(); | ||
// gson.fromJson(text, Model.class); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.readValue(text, Model.class); | ||
} | ||
|
||
public static class Model { | ||
public ClassLoader loader; | ||
} | ||
} |