Jackson deserialization for ReconType

This commit is contained in:
Antonin Delpeuch 2018-10-21 16:36:59 +01:00
parent 0dae0811b0
commit 599edd374f

View File

@ -33,10 +33,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.model;
import org.json.JSONObject;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.util.ParsingUtilities;
/**
* This represents a type from the reconciliation
@ -49,20 +52,17 @@ public class ReconType {
@JsonProperty("name")
public String name;
public ReconType(String id, String name) {
@JsonCreator
public ReconType(
@JsonProperty("id")
String id,
@JsonProperty("name")
String name) {
this.id = id;
this.name = name;
}
static public ReconType load(JSONObject obj) throws Exception {
if (obj == null) {
return null;
}
ReconType type = new ReconType(
obj.getString("id"),
obj.getString("name")
);
return type;
static public ReconType load(String json) throws IOException {
return ParsingUtilities.mapper.readValue(json, ReconType.class);
}
}