Skip to content

Commit

Permalink
1.2.25
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Feb 6, 2017
1 parent da4151d commit d9bc118
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-->
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.25.internal.v9</version>
<version>1.2.25</version>

<packaging>jar</packaging>
<name>fastjson</name>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/alibaba/fastjson/parser/ParserConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
* @author wenshao[szujobs@hotmail.com]
*/
public class ParserConfig {

public final static String DENY_PROPERTY = "fastjson.parser.deny";
public final static String AUTOTYPE_ACCEPT = "fastjson.parser.autoTypeAccept";
public final static String AUTOTYPE_SUPPORT_PROPERTY = "fastjson.parser.autoTypeSupport";
Expand All @@ -132,7 +132,11 @@ public class ParserConfig {
}
{
String property = IOUtils.getStringProperty(AUTOTYPE_ACCEPT);
AUTO_TYPE_ACCEPT_LIST = splitItemsFormProperty(property);
String[] items = splitItemsFormProperty(property);
if (items == null) {
items = new String[0];
}
AUTO_TYPE_ACCEPT_LIST = items;
}
}

Expand All @@ -159,7 +163,7 @@ public static ParserConfig getGlobalInstance() {

private boolean autoTypeSupport = AUTO_SUPPORT;
private String[] denyList = "bsh,com.mchange,com.sun.,java.lang.Thread,java.net.Socket,java.rmi,javax.xml,org.apache.bcel,org.apache.commons.beanutils,org.apache.commons.collections.Transformer,org.apache.commons.collections.functors,org.apache.commons.collections4.comparators,org.apache.commons.fileupload,org.apache.myfaces.context.servlet,org.apache.tomcat,org.apache.wicket.util,org.codehaus.groovy.runtime,org.hibernate,org.jboss,org.mozilla.javascript,org.python.core,org.springframework".split(",");
private String[] acceptList = new String[0];
private String[] acceptList = AUTO_TYPE_ACCEPT_LIST;

public ParserConfig(){
this(null, null);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/alibaba/fastjson/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ private static void addBaseClassMappings() {
java.util.TreeSet.class,
java.util.concurrent.TimeUnit.class,
java.util.concurrent.ConcurrentHashMap.class,
java.util.concurrent.ConcurrentSkipListMap.class,
java.util.concurrent.ConcurrentSkipListSet.class,
loadClass("java.util.concurrent.ConcurrentSkipListMap"),
loadClass("java.util.concurrent.ConcurrentSkipListSet"),
java.util.concurrent.atomic.AtomicInteger.class,
java.util.concurrent.atomic.AtomicLong.class,
java.util.Collections.EMPTY_MAP.getClass(),
Expand All @@ -1024,6 +1024,7 @@ private static void addBaseClassMappings() {
java.sql.Date.class,
java.sql.Timestamp.class,
java.text.SimpleDateFormat.class,
com.alibaba.fastjson.JSONObject.class,
loadClass("java.awt.Rectangle"),
loadClass("java.awt.Point"),
loadClass("java.awt.Font"),
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/alibaba/json/bvt/fullSer/ToJavaObjectTest.java
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class WriteClassNameTest_Collection extends TestCase {
protected void setUp() throws Exception {
ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection");
com.alibaba.fastjson.parser.ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Collection");
}

public void test_list() throws Exception {
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/com/alibaba/json/test/a/CompilerTest.java
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;
}
}
24 changes: 24 additions & 0 deletions src/test/java/com/alibaba/json/test/a/GsonTest.java
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;
}
}

0 comments on commit d9bc118

Please sign in to comment.