Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class JsonFieldHolder {
public boolean shouldParse;
public boolean shouldSerialize;
public Type type;
public Type subType;

public String fill(Element element, Elements elements, Types types, String[] fieldNames, TypeMirror typeConverterType, JsonObjectHolder objectHolder, boolean shouldParse, boolean shouldSerialize) {
if (fieldNames == null || fieldNames.length == 0) {
Expand All @@ -44,6 +45,11 @@ public String fill(Element element, Elements elements, Types types, String[] fie
getterMethod = getGetter(element, elements);

type = Type.typeFor(element.asType(), typeConverterType, elements, types);
subType = type;

if (type instanceof ContainerType) {
subType = ((ContainerType) type).subType;
}

Type typeToCheck = type;
boolean hasSubtypes = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private TypeSpec getTypeSpec() {
// TypeConverters could be expensive to create, so just use one per class
Set<ClassName> typeConvertersUsed = new HashSet<>();
for (JsonFieldHolder fieldHolder : mJsonObjectHolder.fieldMap.values()) {
if (fieldHolder.type instanceof TypeConverterFieldType) {
typeConvertersUsed.add(((TypeConverterFieldType)fieldHolder.type).getTypeConverterClassName());
if (fieldHolder.subType instanceof TypeConverterFieldType) {
typeConvertersUsed.add(((TypeConverterFieldType)fieldHolder.subType).getTypeConverterClassName());
}
}
for (ClassName typeConverter : typeConvertersUsed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public abstract class Type {
public static Type typeFor(TypeMirror typeMirror, TypeMirror typeConverterType, Elements elements, Types types) {
TypeMirror genericClassTypeMirror = types.erasure(typeMirror);

boolean hasTypeConverter = typeConverterType != null && !typeConverterType.toString().equals("void");
boolean isCollection = !genericClassTypeMirror.toString().equals(typeMirror.toString()) || (typeMirror instanceof ArrayType);

if (!hasTypeConverter && isCollection) {
return ContainerType.containerTypeFor(typeMirror, genericClassTypeMirror, elements, types);
if (isCollection) {
return ContainerType.containerTypeFor(typeMirror, typeConverterType, genericClassTypeMirror, elements, types);
} else {
return FieldType.fieldTypeFor(typeMirror, typeConverterType, elements, types);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class ContainerType extends Type {

public Type subType;

public static ContainerType containerTypeFor(TypeMirror typeMirror, TypeMirror genericClassTypeMirror, Elements elements, Types types) {
public static ContainerType containerTypeFor(TypeMirror typeMirror, TypeMirror typeConverterType, TypeMirror genericClassTypeMirror, Elements elements, Types types) {
ContainerType containerType = null;
switch (genericClassTypeMirror.toString()) {
case "java.util.List":
Expand Down Expand Up @@ -54,7 +54,7 @@ public static ContainerType containerTypeFor(TypeMirror typeMirror, TypeMirror g
}

if (containerType != null) {
containerType.subType = Type.typeFor(typeMirror, null, elements, types);
containerType.subType = Type.typeFor(typeMirror, typeConverterType, elements, types);
}

return containerType;
Expand Down