Skip to content

Commit

Permalink
Ability to set custom map/collection type on non parameterized types
Browse files Browse the repository at this point in the history
  • Loading branch information
hevav committed Aug 31, 2023
1 parent b21627b commit c6da5af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ public Object readByType(@Nullable Field owner, @Nullable Object holder, Type ty
}
} else if (type instanceof Class<?> clazz) {
if (Map.class.isAssignableFrom(clazz)) {
return this.readMap(owner);
return this.readMapByType(owner, type);
} else if (List.class.isAssignableFrom(clazz)) {
return this.readList(owner);
return this.readCollectionByType(owner, type, clazz);
} else if (String.class.isAssignableFrom(clazz)) {
return this.readString(owner);
} else if (Character.class.isAssignableFrom(clazz) || char.class.isAssignableFrom(clazz)) {
Expand Down Expand Up @@ -257,8 +257,8 @@ public Object readByType(@Nullable Field owner, @Nullable Object holder, Type ty
}

@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
private Collection<Object> readCollectionByType(Field owner, ParameterizedType parameterizedType, Class<?> clazz) {
Type collectionEntryType = GenericUtils.getParameterType(Collection.class, parameterizedType, 0);
private Collection<Object> readCollectionByType(Field owner, Type type, Class<?> clazz) {
Type collectionEntryType = GenericUtils.getParameterType(Collection.class, type, 0);
if (owner != null) {
CollectionType collectionType = owner.getAnnotation(CollectionType.class);
if (collectionType != null) {
Expand All @@ -270,7 +270,7 @@ private Collection<Object> readCollectionByType(Field owner, ParameterizedType p
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new SerializableReadException(e);
}
} else {
} else if (Collection.class.isAssignableFrom(owner.getType())) {
try {
//noinspection unchecked
return this.readCollection(owner,
Expand All @@ -293,9 +293,9 @@ private Collection<Object> readCollectionByType(Field owner, ParameterizedType p
}

@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
private Map<Object, Object> readMapByType(Field owner, ParameterizedType parameterizedType) {
Type mapKeyType = GenericUtils.getParameterType(Map.class, parameterizedType, 0);
Type mapValueType = GenericUtils.getParameterType(Map.class, parameterizedType, 1);
private Map<Object, Object> readMapByType(Field owner, Type type) {
Type mapKeyType = GenericUtils.getParameterType(Map.class, type, 0);
Type mapValueType = GenericUtils.getParameterType(Map.class, type, 1);
if (owner != null) {
MapType mapType = owner.getAnnotation(MapType.class);
if (mapType != null) {
Expand All @@ -306,7 +306,7 @@ private Map<Object, Object> readMapByType(Field owner, ParameterizedType paramet
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new SerializableReadException(e);
}
} else {
} else if (Map.class.isAssignableFrom(owner.getType())) {
try {
//noinspection unchecked
return this.readMap(owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public static Type getParameterType(Class<?> parent, Type type, int index) {
}
}

return null;
return Object.class;
}
}

0 comments on commit c6da5af

Please sign in to comment.