@@ -66,7 +66,8 @@ public int resolveUnion(Schema union, Object datum) {
6666 for (int i = 0 , len = schemas .size (); i < len ; i ++) {
6767 if (schemas .get (i ).getType () == Type .STRING ) {
6868 return i ;
69- } else if (schemas .get (i ).getType () == Type .DOUBLE ) {
69+ }
70+ if (schemas .get (i ).getType () == Type .DOUBLE ) {
7071 subOptimal = i ;
7172 }
7273 }
@@ -80,47 +81,51 @@ public int resolveUnion(Schema union, Object datum) {
8081
8182 @ Override
8283 protected void write (Schema schema , Object datum , Encoder out ) throws IOException {
84+ if (schema .getType () == Type .ENUM ) {
85+ super .write (schema , GENERIC_DATA .createEnum (datum .toString (), schema ), out );
86+ return ;
87+ }
88+ if (datum instanceof String ) {
89+ String str = (String ) datum ;
90+ final int len = str .length ();
91+ if (schema .getType () == Type .ARRAY && schema .getElementType ().getType () == Type .INT ) {
92+ ArrayList <Integer > chars = new ArrayList <>(len );
93+ for (int i = 0 ; i < len ; ++i ) {
94+ chars .add ((int ) str .charAt (i ));
95+ }
96+ super .write (schema , chars , out );
97+ return ;
98+ }
99+ if (len == 1 && schema .getType () == Type .INT ) {
100+ super .write (schema , (int ) str .charAt (0 ), out );
101+ return ;
102+ }
103+ }
83104 if (datum instanceof Number ) {
105+ Number n = (Number ) datum ;
84106 switch (schema .getType ()) {
85107 case LONG :
86- super .write (schema , ((( Number ) datum ) .longValue () ), out );
108+ super .write (schema , n .longValue (), out );
87109 return ;
88110 case INT :
89- super .write (schema , ((( Number ) datum ) .intValue () ), out );
111+ super .write (schema , n .intValue (), out );
90112 return ;
91113 case FLOAT :
92- super .write (schema , ((( Number ) datum ) .floatValue () ), out );
114+ super .write (schema , n .floatValue (), out );
93115 return ;
94116 case DOUBLE :
95- super .write (schema , ((( Number ) datum ) .doubleValue () ), out );
117+ super .write (schema , n .doubleValue (), out );
96118 return ;
97119 case STRING :
98120 super .write (schema , datum .toString (), out );
99121 return ;
122+ default :
100123 }
101124 }
102125 // Handle stringable classes
103126 if (schema .getType () == Type .STRING && datum != null && datum .getClass ().getAnnotation (Stringable .class ) != null ) {
104127 super .write (schema , datum .toString (), out );
105128 return ;
106- } else if (schema .getType () == Type .ENUM ) {
107- super .write (schema , GENERIC_DATA .createEnum (datum .toString (), schema ), out );
108- return ;
109- } else if (datum instanceof String ) {
110- String str = (String ) datum ;
111- final int len = str .length ();
112- if (schema .getType () == Type .ARRAY && schema .getElementType ().getType () == Type .INT ) {
113- ArrayList <Integer > chars = new ArrayList <>(len );
114- for (int i = 0 ; i < len ; ++i ) {
115- chars .add ((int ) str .charAt (i ));
116- }
117- super .write (schema , chars , out );
118- return ;
119- }
120- if (len == 1 && schema .getType () == Type .INT ) {
121- super .write (schema , (int ) str .charAt (0 ), out );
122- return ;
123- }
124129 }
125130 super .write (schema , datum , out );
126131 }
0 commit comments