Various serialization fixes

This commit is contained in:
Antonin Delpeuch 2018-10-04 17:13:43 +01:00
parent 1790799bfe
commit fec28b99bc
10 changed files with 43 additions and 12 deletions

View File

@ -41,6 +41,7 @@ import java.util.stream.Collectors;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
@ -69,8 +70,9 @@ public class Engine {
public final static String MODE_RECORD_BASED = "record-based";
protected Project _project;
@JsonProperty("facets")
protected List<Facet> _facets = new LinkedList<Facet>();
@JsonValue
@JsonIgnore
protected EngineConfig _config = new EngineConfig(Collections.emptyList(), Mode.RowBased);
static public String modeToString(Mode mode) {
@ -84,6 +86,7 @@ public class Engine {
_project = project;
}
@JsonProperty("engine-mode")
public Mode getMode() {
return _config.getMode();
}

View File

@ -231,16 +231,18 @@ public class ListFacet implements Facet {
@JsonProperty("choiceCount")
@JsonInclude(Include.NON_NULL)
public Integer getChoiceCount() {
if (_errorMessage == null && _choices.size() > getLimit())
if (_errorMessage == null && _choices.size() > getLimit()) {
return _choices.size();
}
return null;
}
@JsonProperty("choices")
@JsonInclude(Include.NON_NULL)
public List<NominalFacetChoice> getChoices() {
if (getError() == null)
if (getError() == null) {
return _choices;
}
return null;
}

View File

@ -43,14 +43,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.ProjectManager;
import com.google.refine.preference.PreferenceStore;
import com.google.refine.preference.TopList;
public class GetPreferenceCommand extends Command {
protected static class PreferenceValue {
@JsonProperty("value")
protected Object pref;
protected Object value;
protected PreferenceValue(Object o) {
pref = o;
protected PreferenceValue(Object pref) {
if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean || pref instanceof TopList) {
value = pref;
} else {
value = pref.toString();
}
}
}

View File

@ -37,6 +37,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.RefineServlet;
abstract public class HttpHeadersSupport {
@ -44,8 +47,11 @@ abstract public class HttpHeadersSupport {
static final protected Map<String, HttpHeaderInfo> s_headers = new HashMap<String, HttpHeaderInfo>();
static public class HttpHeaderInfo {
@JsonIgnore
final public String name;
@JsonProperty("header")
final public String header;
@JsonProperty("defaultValue")
final public String defaultValue;
HttpHeaderInfo(String header, String defaultValue) {

View File

@ -39,6 +39,9 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.grel.Parser;
import clojure.lang.IFn;
@ -47,8 +50,11 @@ import clojure.lang.RT;
abstract public class MetaParser {
static public class LanguageInfo {
@JsonProperty("name")
final public String name;
@JsonIgnore
final public LanguageSpecificParser parser;
@JsonProperty("defaultExpression")
final public String defaultExpression;
LanguageInfo(String name, LanguageSpecificParser parser, String defaultExpression) {

View File

@ -42,6 +42,9 @@ import org.apache.commons.io.FileUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRawValue;
import com.google.refine.ProjectManager;
import com.google.refine.model.Project;
import com.google.refine.model.metadata.ProjectMetadata;
@ -77,6 +80,11 @@ public class ImportingJob {
dir.mkdirs();
}
@JsonProperty("config")
@JsonRawValue
public String getJsonConfig() {
return config.toString();
}
public JSONObject getOrCreateDefaultConfig() {
return config;

View File

@ -149,9 +149,9 @@ public class ReconOperation extends EngineDependentOperation {
"{\n" +
" \"action\" : \"createFacet\",\n" +
" \"facetConfig\" : {\n" +
" \"columnName\" : \"researcher\",\n" +
" \"columnName\" : \"" + _columnName + "\",\n" +
" \"expression\" : \"forNonBlank(cell.recon.judgment, v, v, if(isNonBlank(value), \\\"(unreconciled)\\\", \\\"(blank)\\\"))\",\n" +
" \"name\" : \"researcher: judgment\"\n" +
" \"name\" : \"" + _columnName + ": judgment\"\n" +
" },\n" +
" \"facetOptions\" : {\n" +
" \"scroll\" : false\n" +
@ -162,10 +162,10 @@ public class ReconOperation extends EngineDependentOperation {
"{\n" +
" \"action\" : \"createFacet\",\n" +
" \"facetConfig\" : {\n" +
" \"columnName\" : \"researcher\",\n" +
" \"columnName\" : \"" + _columnName + "\",\n" +
" \"expression\" : \"cell.recon.best.score\",\n" +
" \"mode\" : \"range\",\n" +
" \"name\" : \"researcher: best candidate's score\"\n" +
" \"name\" : \"" + _columnName + ": best candidate's score\"\n" +
" },\n" +
" \"facetType\" : \"range\"\n" +
"}";

View File

@ -79,7 +79,7 @@ public class PreferenceStore {
private Object wrapJSONArray(Object value) {
ObjectMapper mapper = new ObjectMapper();
if(value != null && value instanceof JSONArray) {
if(value != null && (value instanceof JSONArray || value instanceof JSONObject)) {
try {
return mapper.readValue(value.toString(), JsonNode.class);
} catch (IOException e) {

View File

@ -107,6 +107,7 @@ public class Pool {
for (Recon recon : recons2) {
ParsingUtilities.saveWriter.writeValue(writer, recon);
writer.write('\n');
}
}

View File

@ -33,7 +33,7 @@ public class ListFacetTests extends RefineTest {
+ "\"expression\":\"value+\\\"bar\\\"\","
+ "\"columnName\":\"Column A\","
+ "\"invert\":false,"
+ "\"error\":\"No column named Column A\"}\" are not equal as JSON strings.\n" +
+ "\"error\":\"No column named Column A\"" +
"}";
private static String jsonFacet = "{"