File tree Expand file tree Collapse file tree
main/java/com/alibaba/fastjson/util
test/java/com/alibaba/json/bvt/issue_1200 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212import java .lang .reflect .TypeVariable ;
1313import java .util .Arrays ;
1414
15+ import com .alibaba .fastjson .JSONAware ;
1516import com .alibaba .fastjson .annotation .JSONField ;
1617
1718public class FieldInfo implements Comparable <FieldInfo > {
@@ -55,7 +56,7 @@ public FieldInfo(String name, //
5556 this .field = field ;
5657 this .ordinal = ordinal ;
5758
58- isEnum = fieldClass .isEnum ();
59+ isEnum = fieldClass .isEnum () && ! JSONAware . class . isAssignableFrom ( fieldClass ) ;
5960
6061 fieldAnnotation = null ;
6162 methodAnnotation = null ;
@@ -208,7 +209,7 @@ public FieldInfo(String name, //
208209 this .fieldClass = TypeUtils .getClass (genericFieldType );
209210 this .fieldType = genericFieldType ;
210211
211- isEnum = fieldClass .isEnum ();
212+ isEnum = fieldClass .isEnum () && ! JSONAware . class . isAssignableFrom ( fieldClass ) ;
212213 return ;
213214 }
214215 }
@@ -229,7 +230,9 @@ public FieldInfo(String name, //
229230 this .fieldType = genericFieldType ;
230231 this .fieldClass = fieldClass ;
231232
232- isEnum = (!fieldClass .isArray ()) && fieldClass .isEnum ();
233+ isEnum = (!fieldClass .isArray ())
234+ && fieldClass .isEnum ()
235+ && !JSONAware .class .isAssignableFrom (fieldClass );
233236 }
234237
235238 public static Type getFieldType (Class <?> clazz , Type type , Type fieldType ) {
Original file line number Diff line number Diff line change 1+ package com .alibaba .json .bvt .issue_1200 ;
2+
3+ import com .alibaba .fastjson .JSON ;
4+ import com .alibaba .fastjson .JSONAware ;
5+ import com .alibaba .fastjson .serializer .SerializerFeature ;
6+ import junit .framework .TestCase ;
7+
8+ /**
9+ * Created by wenshao on 01/06/2017.
10+ */
11+ public class Issue1222 extends TestCase {
12+ public void test_for_issue () throws Exception {
13+ Model model = new Model ();
14+ model .type = Type .A ;
15+ String text = JSON .toJSONString (model , SerializerFeature .WriteEnumUsingToString );
16+ assertEquals ("{\" type\" :\" TypeA\" }" , text );
17+ }
18+
19+ public static class Model {
20+ public Type type ;
21+ }
22+
23+ public static enum Type implements JSONAware {
24+ A , B ;
25+
26+ public String toJSONString () {
27+ return "\" Type" + this .name () + "\" " ;
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments