Jackson deserialization for ListFacetConfig
This commit is contained in:
parent
121dd76fa1
commit
39498233fb
@ -118,6 +118,13 @@ public class ListFacet implements Facet {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@JsonProperty("selection")
|
||||
public void setSelection(List<DecoratedValueWrapper> wrapped) {
|
||||
selection = wrapped.stream()
|
||||
.map(e -> e.value)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeFromJSON(JSONObject o) {
|
||||
name = o.getString("name");
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user