Jackson deserialization for RowRemovalOperation

This commit is contained in:
Antonin Delpeuch 2018-10-22 10:54:44 +01:00
parent 5f19628618
commit 242a3abb7d
2 changed files with 15 additions and 9 deletions

View File

@ -33,11 +33,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.operations.row; package com.google.refine.operations.row;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.json.JSONObject; import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows; import com.google.refine.browsing.FilteredRows;
@ -48,17 +52,17 @@ import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.model.changes.RowRemovalChange; import com.google.refine.model.changes.RowRemovalChange;
import com.google.refine.operations.EngineDependentOperation; import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.util.ParsingUtilities;
public class RowRemovalOperation extends EngineDependentOperation { public class RowRemovalOperation extends EngineDependentOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws IOException {
JSONObject engineConfig = obj.getJSONObject("engineConfig"); return ParsingUtilities.mapper.readValue(obj.toString(), RowRemovalOperation.class);
return new RowRemovalOperation(
EngineConfig.reconstruct(engineConfig)
);
} }
public RowRemovalOperation(EngineConfig engineConfig) { @JsonCreator
public RowRemovalOperation(
@JsonProperty("engineConfig")
EngineConfig engineConfig) {
super(engineConfig); super(engineConfig);
} }

View File

@ -2,6 +2,8 @@ package com.google.refine.tests.operations.row;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import java.io.IOException;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeSuite;
@ -20,7 +22,7 @@ public class RowRemovalOperationTests extends RefineTest {
} }
@Test @Test
public void serializeRowRemovalOperation() throws JSONException, Exception { public void serializeRowRemovalOperation() throws JSONException, IOException {
Project project = mock(Project.class); Project project = mock(Project.class);
String json = "{" String json = "{"
+ "\"op\":\"core/row-removal\"," + "\"op\":\"core/row-removal\","