Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from vimeo/dev
Browse files Browse the repository at this point in the history
Merge dev into master for 1.1.1
  • Loading branch information
kevinzetterstrom authored Nov 7, 2016
2 parents 086d900 + 8609246 commit 120164b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ The Stag library solves this problem. It leverages annotations to automatically
from jCenter
```groovy
dependencies {
compile 'com.vimeo.stag:stag-library:1.1.0'
apt 'com.vimeo.stag:stag-library-compiler:1.1.0'
compile 'com.vimeo.stag:stag-library:1.1.1'
apt 'com.vimeo.stag:stag-library-compiler:1.1.1'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ allprojects {

subprojects {
group = 'com.vimeo.stag'
version = '1.1.0'
version = '1.1.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.vimeo.sample.model;

import com.vimeo.stag.GsonAdapterKey;

import java.util.ArrayList;

public class IdenticalFieldTypes {

@GsonAdapterKey
User mUser;

@GsonAdapterKey
User mSecondUser;

@GsonAdapterKey
ArrayList<User> mUsersList;

@GsonAdapterKey
ArrayList<User> mSecondUsersList;

@GsonAdapterKey
ArrayList<Stats> mStatsArrayList;

@GsonAdapterKey
Stats mStats;
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ private MethodSpec getReadMethodSpec(@NotNull TypeName typeName,
private static void addAdapterFields(@NotNull TypeSpec.Builder adapterBuilder,
@NotNull MethodSpec.Builder constructorBuilder,
@NotNull Map<Element, TypeMirror> memberVariables) {
HashSet<TypeMirror> typeSet = new HashSet<>(memberVariables.values());
for (TypeMirror fieldType : typeSet) {
HashSet<TypeMirror> inclusiveTypeSet = new HashSet<>(memberVariables.values());
HashSet<TypeMirror> exclusiveTypeSet = new HashSet<>();

for (TypeMirror fieldType : inclusiveTypeSet) {
if (isNative(fieldType.toString())) {
continue;
}
Expand All @@ -220,6 +222,10 @@ private static void addAdapterFields(@NotNull TypeSpec.Builder adapterBuilder,
fieldType = getInnerListType(fieldType);
}

exclusiveTypeSet.add(fieldType);
}

for (TypeMirror fieldType : exclusiveTypeSet) {
TypeName typeName = getAdapterFieldTypeName(fieldType);
String fieldName = getAdapterField(fieldType);

Expand Down Expand Up @@ -288,13 +294,20 @@ private static String getReadTokenType(@NotNull TypeMirror type) {
@NotNull
private static String getReadCode(@NotNull String prefix, @NotNull String variableName,
@NotNull TypeMirror type) {
if (TypeUtils.getOuterClassType(type).equals(ArrayList.class.getName())) {
String outerClassType = TypeUtils.getOuterClassType(type);
if (outerClassType.equals(ArrayList.class.getName())) {
TypeMirror innerType = getInnerListType(type);
String innerRead = getAdapterRead(innerType);
return prefix + "reader.beginArray();\n" +
prefix + "object." + variableName + " = new java.util.ArrayList<>();\n" +
prefix + "while (reader.hasNext()) {\n" +
prefix + "\tobject." + variableName + ".add(" + innerRead + ");\n" +

prefix + "\ttry {\n" +
prefix + "\t\tobject." + variableName + ".add(" + innerRead + ");\n" +
prefix + "\t} catch(Exception exception) {\n" +
prefix + "\t\tthrow new IOException(\"Error parsing " +
outerClassType + "." + variableName + " JSON!\", exception)\n;" +
prefix + "\t}" +
prefix + "}\n" +
prefix + "reader.endArray();";
} else {
Expand Down

0 comments on commit 120164b

Please sign in to comment.