Jackson deserialization for ReconCandidate
This commit is contained in:
parent
ccc8f6470e
commit
8758ed2cff
@ -37,12 +37,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
import com.google.refine.expr.HasFields;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
public class ReconCandidate implements HasFields {
|
||||
@JsonProperty("id")
|
||||
@ -54,10 +56,19 @@ public class ReconCandidate implements HasFields {
|
||||
@JsonProperty("score")
|
||||
final public double score;
|
||||
|
||||
public ReconCandidate(String topicID, String topicName, String[] typeIDs, double score) {
|
||||
@JsonCreator
|
||||
public ReconCandidate(
|
||||
@JsonProperty("id")
|
||||
String topicID,
|
||||
@JsonProperty("name")
|
||||
String topicName,
|
||||
@JsonProperty("types")
|
||||
String[] typeIDs,
|
||||
@JsonProperty("score")
|
||||
double score) {
|
||||
this.id = topicID;
|
||||
this.name = topicName;
|
||||
this.types = typeIDs;
|
||||
this.types = typeIDs == null ? new String[0] : typeIDs;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
@ -81,15 +92,10 @@ public class ReconCandidate implements HasFields {
|
||||
}
|
||||
|
||||
static public ReconCandidate loadStreaming(String s) throws Exception {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
JsonParser jp = jsonFactory.createJsonParser(s);
|
||||
|
||||
if (jp.nextToken() != JsonToken.START_OBJECT) {
|
||||
return null;
|
||||
}
|
||||
return loadStreaming(jp);
|
||||
return ParsingUtilities.mapper.readValue(s, ReconCandidate.class);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static public ReconCandidate loadStreaming(JsonParser jp) throws Exception {
|
||||
JsonToken t = jp.getCurrentToken();
|
||||
if (t == JsonToken.VALUE_NULL || t != JsonToken.START_OBJECT) {
|
||||
|
@ -36,8 +36,6 @@ package com.google.refine.model.recon;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.google.refine.model.Cell;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.model.Recon;
|
||||
@ -49,22 +47,6 @@ public class DataExtensionReconConfig extends StandardReconConfig {
|
||||
|
||||
private final static String WARN = "Not implemented";
|
||||
|
||||
static public ReconConfig reconstruct(JSONObject obj) throws Exception {
|
||||
JSONObject type = obj.getJSONObject("type");
|
||||
|
||||
ReconType typ = null;
|
||||
if(obj.has("id")) {
|
||||
typ = new ReconType(obj.getString("id"),
|
||||
obj.has("name") ? obj.getString("name") : obj.getString("id"));
|
||||
}
|
||||
|
||||
return new DataExtensionReconConfig(
|
||||
obj.getString("service"),
|
||||
obj.has("identifierSpace") ? obj.getString("identifierSpace") : null,
|
||||
obj.has("schemaSpace") ? obj.getString("schemaSpace") : null,
|
||||
typ);
|
||||
}
|
||||
|
||||
public DataExtensionReconConfig(
|
||||
String service,
|
||||
String identifierSpace,
|
||||
|
Loading…
Reference in New Issue
Block a user