Jackson deserialization for KeyValueColumnizeOperation

This commit is contained in:
Antonin Delpeuch 2018-10-22 13:13:38 +01:00
parent 0cf8c2dd04
commit 50ee6ecc61

View File

@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.operations.cell; package com.google.refine.operations.cell;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -40,6 +41,7 @@ import java.util.Map;
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.expr.ExpressionUtils; import com.google.refine.expr.ExpressionUtils;
@ -50,24 +52,24 @@ import com.google.refine.model.Column;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.model.changes.MassRowColumnChange; import com.google.refine.model.changes.MassRowColumnChange;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities;
public class KeyValueColumnizeOperation extends AbstractOperation { public class KeyValueColumnizeOperation extends AbstractOperation {
final protected String _keyColumnName; final protected String _keyColumnName;
final protected String _valueColumnName; final protected String _valueColumnName;
final protected String _noteColumnName; final protected String _noteColumnName;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws IOException {
return new KeyValueColumnizeOperation( return ParsingUtilities.mapper.readValue(obj.toString(), KeyValueColumnizeOperation.class);
obj.getString("keyColumnName"),
obj.getString("valueColumnName"),
JSONUtilities.getString(obj, "noteColumnName", null)
);
} }
@JsonCreator
public KeyValueColumnizeOperation( public KeyValueColumnizeOperation(
@JsonProperty("keyColumnName")
String keyColumnName, String keyColumnName,
@JsonProperty("valueColumnName")
String valueColumnName, String valueColumnName,
@JsonProperty("noteColumnName")
String noteColumnName String noteColumnName
) { ) {
_keyColumnName = keyColumnName; _keyColumnName = keyColumnName;