Remove duplicate JSON keys. Closes #2068.

This commit is contained in:
Antonin Delpeuch 2019-06-14 11:38:24 +01:00
parent 934bd72ec7
commit 9d76b04a1c
7 changed files with 24 additions and 9 deletions

View File

@ -26,7 +26,7 @@
******************************************************************************/
package com.google.refine.browsing.facets;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@ -63,6 +63,6 @@ public interface FacetConfig {
/**
* The facet type as stored in json.
*/
@JsonProperty("type")
@JsonIgnore // already included by @JsonTypeInfo
public String getJsonType();
}

View File

@ -26,6 +26,7 @@
******************************************************************************/
package com.google.refine.clustering;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
@ -70,6 +71,6 @@ public abstract class ClustererConfig {
/**
* Type string used in Json serialization
*/
@JsonProperty("type")
@JsonIgnore // already added by @JsonTypeInfo
public abstract String getType();
}

View File

@ -35,6 +35,7 @@ package com.google.refine.model;
import java.util.Properties;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
@ -72,7 +73,7 @@ abstract public class AbstractOperation {
throw new UnsupportedOperationException();
}
@JsonProperty("op")
@JsonIgnore // the operation id is already added as "op" by the JsonTypeInfo annotation
public String getOperationId() {
return OperationRegistry.s_opClassToName.get(this.getClass());
}

View File

@ -26,8 +26,8 @@
******************************************************************************/
package com.google.refine.preference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Interface to be extended by all objects stored
@ -40,7 +40,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(
use=JsonTypeInfo.Id.CLASS,
include=JsonTypeInfo.As.PROPERTY,
include=JsonTypeInfo.As.EXISTING_PROPERTY,
property="class")
public interface PreferenceValue {

View File

@ -70,7 +70,7 @@ abstract public class Criterion {
@JsonProperty("reverse")
public boolean reverse = false;
@JsonProperty("valueType")
@JsonIgnore // already added by @JsonTypeInfo
public abstract String getValueType();
// Returns a cached cell index

View File

@ -27,11 +27,13 @@
package com.google.refine.tests.preference;
import java.io.IOException;
import java.util.Collections;
import org.testng.annotations.Test;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.refine.preference.PreferenceValue;
import com.google.refine.preference.TopList;
import com.google.refine.tests.util.TestUtils;
import com.google.refine.util.ParsingUtilities;
@ -50,8 +52,12 @@ public class TopListTests {
+ " \"grel:value.parseJson()[\\\"employment-summary\\\"].join('###')\","
+ " \"grel:\\\"https://pub.orcid.org/\\\"+value+\\\"/employments\\\"\""
+ "]}";
PreferenceValue prefValue = ParsingUtilities.mapper.readValue(json, PreferenceValue.class);
TestUtils.isSerializedTo(
ParsingUtilities.mapper.readValue(json, TopList.class),
prefValue,
json);
String mapJson = "{\"key\":"+json+"}";
TestUtils.isSerializedTo(Collections.singletonMap("key",prefValue), mapJson);
}
}

View File

@ -35,8 +35,11 @@ import java.io.LineNumberReader;
import java.io.StringReader;
import java.io.StringWriter;
import com.fasterxml.jackson.core.JsonFactory.Feature;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
@ -50,7 +53,11 @@ public class TestUtils {
static ObjectMapper mapper = new ObjectMapper();
static {
mapper = mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
mapper = mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
// Reject duplicate fields because the previous implementation with org.json
// does not accept them. It is also cleaner and more compact.
mapper = mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
mapper = mapper.enable(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY);
}
/**