Jackson deserialization for RowReorderOperation

This commit is contained in:
Antonin Delpeuch 2018-10-22 11:26:09 +01:00
parent 5f671e5e81
commit c4429cbdff

View File

@ -33,11 +33,13 @@ 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.util.ArrayList; import java.io.IOException;
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.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
@ -53,20 +55,22 @@ import com.google.refine.model.changes.RowReorderChange;
import com.google.refine.sorting.SortingConfig; import com.google.refine.sorting.SortingConfig;
import com.google.refine.sorting.SortingRecordVisitor; import com.google.refine.sorting.SortingRecordVisitor;
import com.google.refine.sorting.SortingRowVisitor; import com.google.refine.sorting.SortingRowVisitor;
import com.google.refine.util.ParsingUtilities;
public class RowReorderOperation extends AbstractOperation { public class RowReorderOperation extends AbstractOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws IOException {
String mode = obj.getString("mode"); return ParsingUtilities.mapper.readValue(obj.toString(), RowReorderOperation.class);
JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ?
obj.getJSONObject("sorting") : null;
SortingConfig config = SortingConfig.reconstruct(sorting);
return new RowReorderOperation(Engine.stringToMode(mode), config);
} }
final protected Mode _mode; final protected Mode _mode;
final protected SortingConfig _sorting; final protected SortingConfig _sorting;
public RowReorderOperation(Mode mode, SortingConfig sorting) { @JsonCreator
public RowReorderOperation(
@JsonProperty("mode")
Mode mode,
@JsonProperty("sorting")
SortingConfig sorting) {
_mode = mode; _mode = mode;
_sorting = sorting; _sorting = sorting;
} }