@@ -141,7 +141,7 @@ public static ClassDescriptor getEncodingClassDescriptor(Class clazz, boolean in
141
141
for (Extension extension : extensions ) {
142
142
extension .updateClassDescriptor (desc );
143
143
}
144
- // encodingDeduplicate(desc);
144
+ encodingDeduplicate (desc );
145
145
for (Binding binding : desc .allEncoderBindings ()) {
146
146
if (binding .toNames == null ) {
147
147
binding .toNames = new String []{binding .name };
@@ -160,34 +160,74 @@ public static ClassDescriptor getEncodingClassDescriptor(Class clazz, boolean in
160
160
}
161
161
162
162
private static void decodingDeduplicate (ClassDescriptor desc ) {
163
- HashMap <String , Binding > fields = new HashMap <String , Binding >();
164
-
165
- for ( Binding field : new ArrayList < Binding >( desc . fields )) {
166
- if ( fields . containsKey ( field .name )) {
167
- // conflict
168
- if (field .method != null ) {
169
- // this is method, prefer using it
170
- desc .fields . remove ( fields . get ( field . name ));
171
- fields . put ( field .name , field );
172
- } else {
173
- // this is not method, discard it
174
- desc . fields . remove ( field ) ;
175
- }
176
- } else {
177
- fields . put ( field . name , field ) ;
163
+ HashMap <String , Binding > byName = new HashMap <String , Binding >();
164
+ for ( Binding field : desc . fields ) {
165
+ if ( byName . containsKey ( field . name )) {
166
+ throw new JsonException ( " field name conflict: " + field .name );
167
+ }
168
+ byName . put (field .name , field );
169
+ }
170
+ for ( Binding setter : desc .setters ) {
171
+ Binding existing = byName . get ( setter .name );
172
+ if ( existing == null ) {
173
+ byName . put ( setter . name , setter );
174
+ continue ;
175
+ }
176
+ if ( desc . fields . remove ( existing )) {
177
+ continue ;
178
178
}
179
+ throw new JsonException ("setter name conflict: " + setter .name );
179
180
}
180
- for (WrapperDescriptor setter : desc .wrappers ) {
181
- for (Binding parameter : setter .parameters ) {
182
- if (fields .containsKey (parameter .name )) {
183
- desc .fields .remove (fields .get (parameter .name ));
181
+ for (WrapperDescriptor wrapper : desc .wrappers ) {
182
+ for (Binding param : wrapper .parameters ) {
183
+ Binding existing = byName .get (param .name );
184
+ if (existing == null ) {
185
+ byName .put (param .name , param );
186
+ continue ;
187
+ }
188
+ if (desc .fields .remove (existing )) {
189
+ continue ;
184
190
}
191
+ if (desc .setters .remove (existing )) {
192
+ continue ;
193
+ }
194
+ throw new JsonException ("wrapper parameter name conflict: " + param .name );
185
195
}
186
196
}
187
- for (Binding parameter : desc .ctor .parameters ) {
188
- if (fields .containsKey (parameter .name )) {
189
- desc .fields .remove (fields .get (parameter .name ));
197
+ for (Binding param : desc .ctor .parameters ) {
198
+ Binding existing = byName .get (param .name );
199
+ if (existing == null ) {
200
+ byName .put (param .name , param );
201
+ continue ;
202
+ }
203
+ if (desc .fields .remove (existing )) {
204
+ continue ;
205
+ }
206
+ if (desc .setters .remove (existing )) {
207
+ continue ;
208
+ }
209
+ throw new JsonException ("ctor parameter name conflict: " + param .name );
210
+ }
211
+ }
212
+
213
+ private static void encodingDeduplicate (ClassDescriptor desc ) {
214
+ HashMap <String , Binding > byName = new HashMap <String , Binding >();
215
+ for (Binding field : desc .fields ) {
216
+ if (byName .containsKey (field .name )) {
217
+ throw new JsonException ("field name conflict: " + field .name );
218
+ }
219
+ byName .put (field .name , field );
220
+ }
221
+ for (Binding getter : desc .getters ) {
222
+ Binding existing = byName .get (getter .name );
223
+ if (existing == null ) {
224
+ byName .put (getter .name , getter );
225
+ continue ;
226
+ }
227
+ if (desc .fields .remove (existing )) {
228
+ continue ;
190
229
}
230
+ throw new JsonException ("getter name conflict: " + getter .name );
191
231
}
192
232
}
193
233
@@ -313,7 +353,7 @@ private static List<Binding> getGetters(Map<String, Type> lookup, Class clazz, b
313
353
toName = new String (fromNameChars );
314
354
Binding getter = new Binding (clazz , lookup , method .getGenericReturnType ());
315
355
getter .toNames = new String []{toName };
316
- getter .name = methodName + "()" ;
356
+ getter .name = toName ;
317
357
getter .method = method ;
318
358
getters .add (getter );
319
359
}
0 commit comments