This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed backwards incompatibility, fixed nested classes always defaulti…
…ng to fieldoption.all
- Loading branch information
Showing
9 changed files
with
162 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ allprojects { | |
|
||
subprojects { | ||
group = 'com.vimeo.stag' | ||
version = '2.0.0' | ||
version = '2.0.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 28 additions & 1 deletion
29
sample/src/main/java/com/vimeo/sample/model/NestedClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,36 @@ | ||
package com.vimeo.sample.model; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import com.vimeo.stag.UseStag; | ||
import com.vimeo.stag.UseStag.FieldOption; | ||
|
||
@UseStag | ||
public class NestedClass { | ||
|
||
public static class Nested extends NestedClass {} | ||
/** | ||
* This class should have a TypeAdapter created | ||
* for it with FieldOption.ALL | ||
*/ | ||
public static class Nested extends NestedClass { | ||
|
||
} | ||
|
||
@UseStag(FieldOption.SERIALIZED_NAME) | ||
public static class NestedWithAnnotation { | ||
|
||
/** | ||
* This class should have a TypeAdapter created | ||
* for it with FieldOption.SERIALIZED_NAME | ||
*/ | ||
public static class NestedNestedWithoutAnnotation { | ||
|
||
// won't be picked up by stag because it inherits the parent annotation | ||
protected String field; | ||
|
||
@SerializedName("name") | ||
protected String field1; | ||
|
||
} | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
sample/src/main/java/com/vimeo/sample/model/NoUseStagAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.vimeo.sample.model; | ||
|
||
import com.vimeo.stag.GsonAdapterKey; | ||
|
||
/** | ||
* This class should have a TypeAdapter created for it | ||
* for backwards compatibility. | ||
* <p> | ||
* Created by restainoa on 1/30/17. | ||
*/ | ||
public class NoUseStagAnnotation { | ||
|
||
@GsonAdapterKey | ||
protected String field; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
sample/src/test/java/com/vimeo/sample/NoUseStagAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.vimeo.sample; | ||
|
||
import com.vimeo.sample.model.NoUseStagAnnotation; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Created by restainoa on 1/30/17. | ||
*/ | ||
public class NoUseStagAnnotationTest { | ||
|
||
@Test | ||
public void typeAdapterWasNotGenerated() throws Exception { | ||
Utils.verifyNoTypeAdapterGeneration(NoUseStagAnnotation.class); | ||
} | ||
|
||
} |
20 changes: 7 additions & 13 deletions
20
sample/src/test/java/com/vimeo/sample/OuterClassWithInnerModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
package com.vimeo.sample; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.vimeo.sample.model.OuterClassWithInnerModel; | ||
import com.vimeo.sample.stag.generated.Stag; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class OuterClassWithInnerModelTest { | ||
|
||
@Test | ||
public void typeAdapterWasGenerated() throws Exception { | ||
Gson gson = new Gson(); | ||
Stag.Factory factory = new Stag.Factory(); | ||
TypeToken<OuterClassWithInnerModel.InnerModel> innerModelType = | ||
TypeToken.get(OuterClassWithInnerModel.InnerModel.class); | ||
TypeAdapter<OuterClassWithInnerModel.InnerModel> adapter = factory.create(gson, innerModelType); | ||
assertNotNull("Type adapter was not generated by Stag", adapter); | ||
public void innerTypeAdapterWasGenerated() throws Exception { | ||
Utils.verifyTypeAdapterGeneration(OuterClassWithInnerModel.InnerModel.class); | ||
} | ||
|
||
@Test | ||
public void outerTypeAdapterWasNotGenerated() throws Exception { | ||
Utils.verifyNoTypeAdapterGeneration(OuterClassWithInnerModel.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.vimeo.sample; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.TypeAdapter; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.vimeo.sample.stag.generated.Stag; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
/** | ||
* Utils class for testing type adapter generation. | ||
* | ||
* Created by restainoa on 1/30/17. | ||
*/ | ||
public final class Utils { | ||
|
||
private Utils() { | ||
} | ||
|
||
private static <T> TypeAdapter<T> getTypeAdapter(@NonNull Class<T> clazz) { | ||
Gson gson = new Gson(); | ||
Stag.Factory factory = new Stag.Factory(); | ||
TypeToken<T> innerModelType = TypeToken.get(clazz); | ||
return factory.create(gson, innerModelType); | ||
} | ||
|
||
/** | ||
* Verifies that a TypeAdapter was generated for the specified class. | ||
* | ||
* @param clazz the class to check. | ||
* @param <T> the type of the class, used internally. | ||
* @throws Exception throws an exception if an adapter was not generated. | ||
*/ | ||
public static <T> void verifyTypeAdapterGeneration(@NonNull Class<T> clazz) throws Exception { | ||
TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); | ||
assertNotNull("Type adapter was not generated by Stag", typeAdapter); | ||
} | ||
|
||
/** | ||
* Verifies that a TypeAdapter was NOT generated for the specified class. | ||
* | ||
* @param clazz the class to check. | ||
* @param <T> the type of the class, used internally. | ||
* @throws Exception throws an exception if an adapter was generated. | ||
*/ | ||
public static <T> void verifyNoTypeAdapterGeneration(@NonNull Class<T> clazz) throws Exception { | ||
TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); | ||
assertNull("Type adapter was not generated by Stag", typeAdapter); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters