@@ -66,7 +66,8 @@ public int resolveUnion(Schema union, Object datum) {
66
66
for (int i = 0 , len = schemas .size (); i < len ; i ++) {
67
67
if (schemas .get (i ).getType () == Type .STRING ) {
68
68
return i ;
69
- } else if (schemas .get (i ).getType () == Type .DOUBLE ) {
69
+ }
70
+ if (schemas .get (i ).getType () == Type .DOUBLE ) {
70
71
subOptimal = i ;
71
72
}
72
73
}
@@ -80,47 +81,51 @@ public int resolveUnion(Schema union, Object datum) {
80
81
81
82
@ Override
82
83
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
+ }
83
104
if (datum instanceof Number ) {
105
+ Number n = (Number ) datum ;
84
106
switch (schema .getType ()) {
85
107
case LONG :
86
- super .write (schema , ((( Number ) datum ) .longValue () ), out );
108
+ super .write (schema , n .longValue (), out );
87
109
return ;
88
110
case INT :
89
- super .write (schema , ((( Number ) datum ) .intValue () ), out );
111
+ super .write (schema , n .intValue (), out );
90
112
return ;
91
113
case FLOAT :
92
- super .write (schema , ((( Number ) datum ) .floatValue () ), out );
114
+ super .write (schema , n .floatValue (), out );
93
115
return ;
94
116
case DOUBLE :
95
- super .write (schema , ((( Number ) datum ) .doubleValue () ), out );
117
+ super .write (schema , n .doubleValue (), out );
96
118
return ;
97
119
case STRING :
98
120
super .write (schema , datum .toString (), out );
99
121
return ;
122
+ default :
100
123
}
101
124
}
102
125
// Handle stringable classes
103
126
if (schema .getType () == Type .STRING && datum != null && datum .getClass ().getAnnotation (Stringable .class ) != null ) {
104
127
super .write (schema , datum .toString (), out );
105
128
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
- }
124
129
}
125
130
super .write (schema , datum , out );
126
131
}
0 commit comments