DashboardTabPaneSaver implements ElementTypeAdapter<DashboardTabPane> { @Override public DashboardTabPane deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonTabs = json.getAsJsonArray(); List<Tab> tabs = new ArrayList<>(jsonTabs.size()); for (JsonElement i : jsonTabs) { JsonObject obj = i.getAsJsonObject(); String title = obj.get("title").getAsString(); DashboardTab tab = new DashboardTab(title); tab.setWidgetPane(context.deserialize(obj.get("widgetPane"), WidgetPane.class)); tab.setSourcePrefix(obj.get("autoPopulatePrefix").getAsString()); tab.setAutoPopulate(obj.get("autoPopulate").getAsBoolean()); tabs.add(tab); } return new DashboardTabPane(tabs.toArray(new Tab[]{})); }  @Override JsonElement serialize(DashboardTabPane src, JsonSerializationContext context); @Override DashboardTabPane deserialize(JsonElement json, JsonDeserializationContext context);  }
@Test public void testDeserialize() throws Exception { Reader reader = new InputStreamReader(getClass().getResourceAsStream("/test.json"), "UTF-8"); DashboardData data = JsonBuilder.forSaveFile().fromJson(reader, DashboardData.class); DashboardTabPane dashboard = data.getTabPane(); assertEquals(2 + 1, dashboard.getTabs().size(), "There should be 2 dashboard tabs and 1 adder tab"); DashboardTab firstTab = (DashboardTab) dashboard.getTabs().get(0); DashboardTab secondTab = (DashboardTab) dashboard.getTabs().get(1); assertEquals("First Tab", firstTab.getTitle(), "Title of the first tab was wrong"); assertEquals("Second Tab", secondTab.getTitle(), "Title of the second tab was wrong"); assertFalse(firstTab.isAutoPopulate(), "The first tab should not be autopopulating"); assertTrue(secondTab.isAutoPopulate(), "The second tab should be autopopulating"); assertEquals("", firstTab.getSourcePrefix(), "The first tab should not have a source prefix"); assertEquals("foo", secondTab.getSourcePrefix(), "The second tab should autopopulate from 'foo'"); assertEquals(1, firstTab.getWidgetPane().getTiles().size(), "There should only be one tile"); Tile tile = firstTab.getWidgetPane().getTiles().get(0); Component content = tile.getContent(); assertTrue(content instanceof DummyBooleanBox); }