@@ -254,23 +254,24 @@ public Object readByType(@Nullable Field owner, @Nullable Object holder, Type ty
254254
255255 @ SuppressWarnings ("unchecked" )
256256 @ SuppressFBWarnings ("NP_LOAD_OF_KNOWN_NULL_VALUE" )
257- private Collection <Object > readCollectionByType (Field owner , Type type , Class <?> clazz ) {
258- Type collectionEntryType = GenericUtils .getParameterType (Collection .class , type , 0 );
257+ private Map <Object , Object > readMapByType (Field owner , Type type ) {
258+ Type mapKeyType = GenericUtils .getParameterType (Map .class , type , 0 );
259+ Type mapValueType = GenericUtils .getParameterType (Map .class , type , 1 );
259260 if (owner != null ) {
260- CollectionType collectionType = owner .getAnnotation (CollectionType .class );
261- if (collectionType != null ) {
261+ MapType mapType = owner .getAnnotation (MapType .class );
262+ if (mapType != null ) {
262263 try {
263- var constructor = collectionType .value ().getDeclaredConstructor ();
264+ var constructor = mapType .value ().getDeclaredConstructor ();
264265 constructor .setAccessible (true );
265- return this .readCollection (owner , (Collection <Object >) constructor .newInstance (), collectionEntryType );
266+ return this .readMap (owner , (Map <Object , Object >) constructor .newInstance (), mapKeyType , mapValueType );
266267 } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
267268 throw new SerializableReadException (e );
268269 }
269- } else if (Collection .class .isAssignableFrom (owner .getType ())) {
270+ } else if (Map .class .isAssignableFrom (owner .getType ())) {
270271 try {
271272 Constructor <?> constructor = owner .getType ().getDeclaredConstructor ();
272273 constructor .setAccessible (true );
273- return this .readCollection (owner , (Collection <Object >) constructor .newInstance (), collectionEntryType );
274+ return this .readMap (owner , (Map <Object , Object >) constructor .newInstance (), mapKeyType , mapValueType );
274275 } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
275276 throw new SerializableReadException (e );
276277 } catch (NoSuchMethodException e ) {
@@ -279,31 +280,28 @@ private Collection<Object> readCollectionByType(Field owner, Type type, Class<?>
279280 }
280281 }
281282
282- return Set .class .isAssignableFrom (clazz ) ? this .readSet (owner , collectionEntryType )
283- : Queue .class .isAssignableFrom (clazz ) ? this .readDeque (owner , collectionEntryType )
284- : this .readList (owner , collectionEntryType );
283+ return this .readMap (owner , mapKeyType , mapValueType );
285284 }
286285
287286 @ SuppressWarnings ("unchecked" )
288287 @ SuppressFBWarnings ("NP_LOAD_OF_KNOWN_NULL_VALUE" )
289- private Map <Object , Object > readMapByType (Field owner , Type type ) {
290- Type mapKeyType = GenericUtils .getParameterType (Map .class , type , 0 );
291- Type mapValueType = GenericUtils .getParameterType (Map .class , type , 1 );
288+ private Collection <Object > readCollectionByType (Field owner , Type type , Class <?> clazz ) {
289+ Type collectionEntryType = GenericUtils .getParameterType (Collection .class , type , 0 );
292290 if (owner != null ) {
293- MapType mapType = owner .getAnnotation (MapType .class );
294- if (mapType != null ) {
291+ CollectionType collectionType = owner .getAnnotation (CollectionType .class );
292+ if (collectionType != null ) {
295293 try {
296- var constructor = mapType .value ().getDeclaredConstructor ();
294+ var constructor = collectionType .value ().getDeclaredConstructor ();
297295 constructor .setAccessible (true );
298- return this .readMap (owner , (Map <Object , Object >) constructor .newInstance (), mapKeyType , mapValueType );
296+ return this .readCollection (owner , (Collection <Object >) constructor .newInstance (), collectionEntryType );
299297 } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
300298 throw new SerializableReadException (e );
301299 }
302- } else if (Map .class .isAssignableFrom (owner .getType ())) {
300+ } else if (Collection .class .isAssignableFrom (owner .getType ())) {
303301 try {
304302 Constructor <?> constructor = owner .getType ().getDeclaredConstructor ();
305303 constructor .setAccessible (true );
306- return this .readMap (owner , (Map <Object , Object >) constructor .newInstance (), mapKeyType , mapValueType );
304+ return this .readCollection (owner , (Collection <Object >) constructor .newInstance (), collectionEntryType );
307305 } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
308306 throw new SerializableReadException (e );
309307 } catch (NoSuchMethodException e ) {
@@ -312,7 +310,9 @@ private Map<Object, Object> readMapByType(Field owner, Type type) {
312310 }
313311 }
314312
315- return this .readMap (owner , mapKeyType , mapValueType );
313+ return Set .class .isAssignableFrom (clazz ) ? this .readSet (owner , collectionEntryType )
314+ : Queue .class .isAssignableFrom (clazz ) ? this .readDeque (owner , collectionEntryType )
315+ : this .readList (owner , collectionEntryType );
316316 }
317317
318318 public Object readGuessingType () {
@@ -343,28 +343,6 @@ public <C extends Map<Object, Object>> C readMap(C result, Type keyType, Type va
343343
344344 public abstract <C extends Map <Object , Object >> C readMap (@ Nullable Field owner , C result , Type keyType , Type valueType );
345345
346- public <C extends Collection <Object >> C readCollection (@ Nullable Field owner , C result ) {
347- return this .readCollection (owner , result , Object .class );
348- }
349-
350- public <C extends Collection <Object >> C readCollection (C result , Type type ) {
351- return this .readCollection (null , result , type );
352- }
353-
354- public abstract <C extends Collection <Object >> C readCollection (@ Nullable Field owner , C result , Type type );
355-
356- public List <Object > readList (@ Nullable Field owner ) {
357- return this .readList (owner , Object .class );
358- }
359-
360- public List <Object > readList (Type type ) {
361- return this .readList (null , type );
362- }
363-
364- public List <Object > readList (@ Nullable Field owner , Type type ) {
365- return this .readCollection (owner , new ArrayList <>(), type );
366- }
367-
368346 public Set <Object > readSet (@ Nullable Field owner ) {
369347 return this .readSet (owner , Object .class );
370348 }
@@ -389,6 +367,28 @@ public Deque<Object> readDeque(@Nullable Field owner, Type type) {
389367 return this .readCollection (owner , new ArrayDeque <>(), type );
390368 }
391369
370+ public List <Object > readList (@ Nullable Field owner ) {
371+ return this .readList (owner , Object .class );
372+ }
373+
374+ public List <Object > readList (Type type ) {
375+ return this .readList (null , type );
376+ }
377+
378+ public List <Object > readList (@ Nullable Field owner , Type type ) {
379+ return this .readCollection (owner , new ArrayList <>(), type );
380+ }
381+
382+ public <C extends Collection <Object >> C readCollection (@ Nullable Field owner , C result ) {
383+ return this .readCollection (owner , result , Object .class );
384+ }
385+
386+ public <C extends Collection <Object >> C readCollection (C result , Type type ) {
387+ return this .readCollection (null , result , type );
388+ }
389+
390+ public abstract <C extends Collection <Object >> C readCollection (@ Nullable Field owner , C result , Type type );
391+
392392 public String readString () {
393393 return this .readString (null );
394394 }
@@ -458,8 +458,8 @@ public void skipNode(Class<?> clazz) {
458458 public void skipNode (@ Nullable Field owner , Class <?> clazz ) {
459459 if (Map .class .isAssignableFrom (clazz )) {
460460 this .skipMap (owner );
461- } else if (List .class .isAssignableFrom (clazz )) {
462- this .skipList (owner );
461+ } else if (Collection .class .isAssignableFrom (clazz )) {
462+ this .skipCollection (owner );
463463 } else if (clazz .isEnum ()
464464 || String .class .isAssignableFrom (clazz )
465465 || Boolean .class .isAssignableFrom (clazz ) || boolean .class .isAssignableFrom (clazz )
@@ -477,11 +477,11 @@ public void skipMap() {
477477
478478 public abstract void skipMap (@ Nullable Field owner );
479479
480- public void skipList () {
481- this .skipList (null );
480+ public void skipCollection () {
481+ this .skipCollection (null );
482482 }
483483
484- public abstract void skipList (@ Nullable Field owner );
484+ public abstract void skipCollection (@ Nullable Field owner );
485485
486486 public void skipString () {
487487 this .skipString (null );
0 commit comments