diff --git a/src/test/java/com/github/ravenlab/autogson/test/AutoGsonTest.java b/src/test/java/com/github/ravenlab/autogson/test/AutoGsonTest.java index c867323..df45500 100644 --- a/src/test/java/com/github/ravenlab/autogson/test/AutoGsonTest.java +++ b/src/test/java/com/github/ravenlab/autogson/test/AutoGsonTest.java @@ -6,8 +6,10 @@ import org.junit.Test; import com.github.ravenlab.AutoGson; -import com.github.ravenlab.autogson.test.obj.FooBar; -import com.github.ravenlab.autogson.test.obj.FooBarChild; +import com.github.ravenlab.autogson.test.foo.FooBar; +import com.github.ravenlab.autogson.test.foo.FooBarChild; +import com.github.ravenlab.autogson.test.foo.data.ExtraFooData; +import com.github.ravenlab.autogson.test.foo.data.FooData; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; @@ -78,4 +80,45 @@ public void testInheritance() fail("Class not found or an issue with the original json"); } } + + @Test + public void testInnerCustomClass() + { + FooBar child = new FooBarChild(); + Gson gson = new Gson(); + String json = AutoGson.toJson(gson, child); + + try + { + FooBarChild foo = AutoGson.fromJson(gson, json); + String data = foo.getData().getData(); + assertTrue(data.equals("somedata")); + } + catch (JsonSyntaxException | ClassNotFoundException e) + { + e.printStackTrace(); + fail("Class not found or an issue with the original json"); + } + } + + @Test + public void testInnerCustomClassChild() + { + FooBar child = new FooBarChild(); + Gson gson = new Gson(); + String json = AutoGson.toJson(gson, child); + + try + { + FooBarChild foo = AutoGson.fromJson(gson, json); + FooData fooData = foo.getData(); + System.out.println(fooData.getClass().getName()); + assertTrue(fooData instanceof ExtraFooData); + } + catch (JsonSyntaxException | ClassNotFoundException e) + { + e.printStackTrace(); + fail("Class not found or an issue with the original json"); + } + } } \ No newline at end of file diff --git a/src/test/java/com/github/ravenlab/autogson/test/obj/FooBar.java b/src/test/java/com/github/ravenlab/autogson/test/foo/FooBar.java similarity index 74% rename from src/test/java/com/github/ravenlab/autogson/test/obj/FooBar.java rename to src/test/java/com/github/ravenlab/autogson/test/foo/FooBar.java index 0abecd5..7c86851 100644 --- a/src/test/java/com/github/ravenlab/autogson/test/obj/FooBar.java +++ b/src/test/java/com/github/ravenlab/autogson/test/foo/FooBar.java @@ -1,4 +1,4 @@ -package com.github.ravenlab.autogson.test.obj; +package com.github.ravenlab.autogson.test.foo; public class FooBar { diff --git a/src/test/java/com/github/ravenlab/autogson/test/foo/FooBarChild.java b/src/test/java/com/github/ravenlab/autogson/test/foo/FooBarChild.java new file mode 100644 index 0000000..8c84b3e --- /dev/null +++ b/src/test/java/com/github/ravenlab/autogson/test/foo/FooBarChild.java @@ -0,0 +1,26 @@ +package com.github.ravenlab.autogson.test.foo; + +import com.github.ravenlab.autogson.test.foo.data.ExtraFooData; +import com.github.ravenlab.autogson.test.foo.data.FooData; + +public class FooBarChild extends FooBar { + + private String fooBar; + private ExtraFooData fooData; + public FooBarChild() + { + super(); + this.fooBar = "foobar"; + this.fooData = new ExtraFooData<>("somedata", "someotherdata"); + } + + public String getFooBar() + { + return this.fooBar; + } + + public FooData getData() + { + return this.fooData; + } +} diff --git a/src/test/java/com/github/ravenlab/autogson/test/foo/data/ExtraFooData.java b/src/test/java/com/github/ravenlab/autogson/test/foo/data/ExtraFooData.java new file mode 100644 index 0000000..0ebfce1 --- /dev/null +++ b/src/test/java/com/github/ravenlab/autogson/test/foo/data/ExtraFooData.java @@ -0,0 +1,15 @@ +package com.github.ravenlab.autogson.test.foo.data; + +public class ExtraFooData extends FooData { + + private T extraData; + public ExtraFooData(T data, T extraData) + { + super(data); + } + + public T getExtraData() + { + return this.extraData; + } +} \ No newline at end of file diff --git a/src/test/java/com/github/ravenlab/autogson/test/foo/data/FooData.java b/src/test/java/com/github/ravenlab/autogson/test/foo/data/FooData.java new file mode 100644 index 0000000..91f7115 --- /dev/null +++ b/src/test/java/com/github/ravenlab/autogson/test/foo/data/FooData.java @@ -0,0 +1,15 @@ +package com.github.ravenlab.autogson.test.foo.data; + +public class FooData { + + private T data; + public FooData(T data) + { + this.data = data; + } + + public T getData() + { + return this.data; + } +} \ No newline at end of file diff --git a/src/test/java/com/github/ravenlab/autogson/test/foo/data/package-info.java b/src/test/java/com/github/ravenlab/autogson/test/foo/data/package-info.java new file mode 100644 index 0000000..92c93d4 --- /dev/null +++ b/src/test/java/com/github/ravenlab/autogson/test/foo/data/package-info.java @@ -0,0 +1 @@ +package com.github.ravenlab.autogson.test.foo.data; \ No newline at end of file diff --git a/src/test/java/com/github/ravenlab/autogson/test/obj/FooBarChild.java b/src/test/java/com/github/ravenlab/autogson/test/obj/FooBarChild.java deleted file mode 100644 index 052fffa..0000000 --- a/src/test/java/com/github/ravenlab/autogson/test/obj/FooBarChild.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.ravenlab.autogson.test.obj; - -public class FooBarChild extends FooBar { - - private String fooBar; - public FooBarChild() - { - super(); - this.fooBar = "foobar"; - } - - public String getFooBar() - { - return this.fooBar; - } -}