Skip to content
Browse files

fix testcase

  • Loading branch information...
1 parent 43d3054 commit 00f08fab31d58c288546353d739b132c5f106620 wenshao committed Sep 1, 2012
View
34 src/main/java/com/alibaba/fastjson/serializer/JSONSerializer.java
@@ -48,18 +48,18 @@
private final SerializeWriter out;
- private List<PropertyFilter> propertyFilters = null;
- private List<ValueFilter> valueFilters = null;
- private List<NameFilter> nameFilters = null;
- private List<PropertyPreFilter> propertyPreFilters = null;
+ private List<PropertyFilter> propertyFilters = null;
+ private List<ValueFilter> valueFilters = null;
+ private List<NameFilter> nameFilters = null;
+ private List<PropertyPreFilter> propertyPreFilters = null;
- private int indentCount = 0;
- private String indent = "\t";
+ private int indentCount = 0;
+ private String indent = "\t";
- private String dateFormatPatterm = JSON.DEFFAULT_DATE_FORMAT;
+ private String dateFormatPatterm = JSON.DEFFAULT_DATE_FORMAT;
private DateFormat dateFormat;
- private IdentityHashMap<Object, SerialContext> references = null;
+ private IdentityHashMap<Object, SerialContext> references = null;
private SerialContext context;
public JSONSerializer(){
@@ -292,10 +292,10 @@ public void println() {
if (propertyPreFilters == null) {
propertyPreFilters = new ArrayList<PropertyPreFilter>();
}
-
+
return propertyPreFilters;
}
-
+
public List<PropertyPreFilter> getPropertyPreFiltersDirect() {
return propertyPreFilters;
}
@@ -419,6 +419,20 @@ public ObjectSerializer getObjectWriter(Class<?> clazz) {
}
if (writer == null) {
+ final ClassLoader classLoader = JSON.class.getClassLoader();
+ if (classLoader != Thread.currentThread().getContextClassLoader()) {
+ for (AutowiredObjectSerializer autowired : ServiceLoader.load(AutowiredObjectSerializer.class,
+ classLoader)) {
+ for (Type forType : autowired.getAutowiredFor()) {
+ config.put(forType, autowired);
+ }
+ }
+
+ writer = config.get(clazz);
+ }
+ }
+
+ if (writer == null) {
if (Map.class.isAssignableFrom(clazz)) {
config.put(clazz, MapSerializer.instance);
} else if (List.class.isAssignableFrom(clazz)) {
View
5 src/test/java/com/alibaba/json/bvt/ColorTest.java
@@ -6,10 +6,15 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.ColorSerializer;
+import com.alibaba.fastjson.serializer.JSONSerializer;
public class ColorTest extends TestCase {
public void test_color() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(ColorSerializer.class, serializer.getObjectWriter(Color.class).getClass());
+
Color color = Color.RED;
String text = JSON.toJSONString(color);
System.out.println(text);
View
5 src/test/java/com/alibaba/json/bvt/ColorTest2.java
@@ -6,11 +6,16 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.ColorSerializer;
+import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class ColorTest2 extends TestCase {
public void test_color() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(ColorSerializer.class, serializer.getObjectWriter(Color.class).getClass());
+
Color color = Color.RED;
String text = JSON.toJSONString(color, SerializerFeature.WriteClassName);
System.out.println(text);
View
5 src/test/java/com/alibaba/json/bvt/PointTest.java
@@ -6,10 +6,15 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.PointSerializer;
public class PointTest extends TestCase {
public void test_color() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(PointSerializer.class, serializer.getObjectWriter(Point.class).getClass());
+
Point point = new Point(3, 4);
String text = JSON.toJSONString(point);
View
5 src/test/java/com/alibaba/json/bvt/PointTest2.java
@@ -6,11 +6,16 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.PointSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class PointTest2 extends TestCase {
public void test_point() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(PointSerializer.class, serializer.getObjectWriter(Point.class).getClass());
+
Point point = new Point(3, 4);
String text = JSON.toJSONString(point, SerializerFeature.WriteClassName);
View
5 src/test/java/com/alibaba/json/bvt/RectangleTest.java
@@ -6,11 +6,16 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.RectangleSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class RectangleTest extends TestCase {
public void test_color() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(RectangleSerializer.class, serializer.getObjectWriter(Rectangle.class).getClass());
+
Rectangle v = new Rectangle(3, 4, 100, 200);
String text = JSON.toJSONString(v, SerializerFeature.WriteClassName);
View
6 src/test/java/com/alibaba/json/bvt/serializer/ColorSerializerTest.java
@@ -1,17 +1,23 @@
package com.alibaba.json.bvt.serializer;
+import java.awt.Color;
import java.awt.Rectangle;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.ColorSerializer;
+import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class ColorSerializerTest extends TestCase {
public void test_null() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(ColorSerializer.class, serializer.getObjectWriter(Color.class).getClass());
+
VO vo = new VO();
Assert.assertEquals("{\"value\":null}", JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue));
View
6 src/test/java/com/alibaba/json/bvt/serializer/FontSerializerTest.java
@@ -6,12 +6,18 @@
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.FontSerializer;
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class FontSerializerTest extends TestCase {
public void test_null() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(FontSerializer.class, serializer.getObjectWriter(Font.class).getClass());
+
VO vo = new VO();
Assert.assertEquals("{\"value\":null}", JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue));
View
14 src/test/java/com/alibaba/json/bvt/serializer/RectangleSerializerTest.java
@@ -1,32 +1,36 @@
package com.alibaba.json.bvt.serializer;
-import java.awt.Color;
-import java.awt.Font;
+import java.awt.Rectangle;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.RectangleSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class RectangleSerializerTest extends TestCase {
public void test_null() throws Exception {
+ JSONSerializer serializer = new JSONSerializer();
+ Assert.assertEquals(RectangleSerializer.class, serializer.getObjectWriter(Rectangle.class).getClass());
+
VO vo = new VO();
Assert.assertEquals("{\"value\":null}", JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue));
}
private static class VO {
- private Color value;
+ private Rectangle value;
- public Color getValue() {
+ public Rectangle getValue() {
return value;
}
- public void setValue(Color value) {
+ public void setValue(Rectangle value) {
this.value = value;
}

0 comments on commit 00f08fa

Please sign in to comment.
Something went wrong with that request. Please try again.