diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index 521af7858..768b287a1 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -118,6 +118,13 @@ public class ListFacet implements Facet { .collect(Collectors.toList()); } + @JsonProperty("selection") + public void setSelection(List wrapped) { + selection = wrapped.stream() + .map(e -> e.value) + .collect(Collectors.toList()); + } + @Override public void initializeFromJSON(JSONObject o) { name = o.getString("name"); diff --git a/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java b/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java index 92a77bf63..f462f4710 100644 --- a/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java +++ b/main/tests/server/src/com/google/refine/tests/browsing/facets/ListFacetTests.java @@ -1,14 +1,20 @@ package com.google.refine.tests.browsing.facets; +import java.io.IOException; + import org.json.JSONObject; import org.testng.annotations.Test; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + import com.google.refine.browsing.Engine; import com.google.refine.browsing.facets.Facet; import com.google.refine.browsing.facets.ListFacet.ListFacetConfig; import com.google.refine.model.Project; import com.google.refine.tests.RefineTest; import com.google.refine.tests.util.TestUtils; +import com.google.refine.util.ParsingUtilities; public class ListFacetTests extends RefineTest { @@ -66,14 +72,13 @@ public class ListFacetTests extends RefineTest { } @Test - public void serializeListFacet() { + public void serializeListFacet() throws JsonParseException, JsonMappingException, IOException { Project project = createCSVProject("Column A\n" + "foo\n" + "bar\n"); Engine engine = new Engine(project); - ListFacetConfig facetConfig = new ListFacetConfig(); - facetConfig.initializeFromJSON(new JSONObject(jsonConfig)); + ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class); Facet facet = facetConfig.apply(project); facet.computeChoices(project, engine.getAllFilteredRows()); @@ -82,13 +87,12 @@ public class ListFacetTests extends RefineTest { } @Test - public void serializeListFacetWithError() { + public void serializeListFacetWithError() throws JsonParseException, JsonMappingException, IOException { Project project = createCSVProject("other column\n" + "foo\n" + "bar\n"); - ListFacetConfig facetConfig = new ListFacetConfig(); - facetConfig.initializeFromJSON(new JSONObject(jsonConfig)); + ListFacetConfig facetConfig = ParsingUtilities.mapper.readValue(jsonConfig, ListFacetConfig.class); Facet facet = facetConfig.apply(project); TestUtils.isSerializedTo(facet, jsonFacetError); }