Fix serialization issues in Wikidata extension
This commit is contained in:
parent
f6fc47a8f9
commit
bd5a8f9ece
@ -88,7 +88,7 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Peform edits on Wikidata";
|
return "Peform Wikibase edits";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,6 +27,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entity id value that also comes with a label and possibly types.
|
* An entity id value that also comes with a label and possibly types.
|
||||||
*
|
*
|
||||||
@ -47,6 +49,7 @@ public interface PrefetchedEntityIdValue extends EntityIdValue {
|
|||||||
*
|
*
|
||||||
* @return the preferred label of the entity
|
* @return the preferred label of the entity
|
||||||
*/
|
*/
|
||||||
|
@JsonProperty("label")
|
||||||
public String getLabel();
|
public String getLabel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,5 +59,6 @@ public interface PrefetchedEntityIdValue extends EntityIdValue {
|
|||||||
*
|
*
|
||||||
* Empty lists should be returned for
|
* Empty lists should be returned for
|
||||||
*/
|
*/
|
||||||
|
@JsonProperty("types")
|
||||||
public List<String> getTypes();
|
public List<String> getTypes();
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
|||||||
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.model.Recon;
|
import com.google.refine.model.Recon;
|
||||||
|
|
||||||
@ -72,6 +73,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
return !isMatched();
|
return !isMatched();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("label")
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
if (isMatched()) {
|
if (isMatched()) {
|
||||||
return _recon.match.name;
|
return _recon.match.name;
|
||||||
@ -80,6 +82,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("types")
|
||||||
public List<String> getTypes() {
|
public List<String> getTypes() {
|
||||||
if (isMatched()) {
|
if (isMatched()) {
|
||||||
return Arrays.asList(_recon.match.types);
|
return Arrays.asList(_recon.match.types);
|
||||||
@ -89,6 +92,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("entityType")
|
||||||
public abstract String getEntityType();
|
public abstract String getEntityType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +100,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
*
|
*
|
||||||
* @return the reconciliation id of the reconciled cell
|
* @return the reconciliation id of the reconciled cell
|
||||||
*/
|
*/
|
||||||
|
@JsonProperty("reconInternalId")
|
||||||
public long getReconInternalId() {
|
public long getReconInternalId() {
|
||||||
return getRecon().id;
|
return getRecon().id;
|
||||||
}
|
}
|
||||||
@ -114,6 +119,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
* Returns the id of the reconciled item
|
* Returns the id of the reconciled item
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("id")
|
||||||
public String getId() {
|
public String getId() {
|
||||||
if (isMatched()) {
|
if (isMatched()) {
|
||||||
return _recon.match.id;
|
return _recon.match.id;
|
||||||
@ -126,6 +132,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("siteIri")
|
||||||
public String getSiteIri() {
|
public String getSiteIri() {
|
||||||
if (isMatched()) {
|
if (isMatched()) {
|
||||||
return _recon.identifierSpace;
|
return _recon.identifierSpace;
|
||||||
@ -135,6 +142,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("iri")
|
||||||
public String getIri() {
|
public String getIri() {
|
||||||
return getSiteIri() + getId();
|
return getSiteIri() + getId();
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ import org.wikidata.wdtk.datamodel.helpers.Hash;
|
|||||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An EntityIdValue that we have obtained from a suggest widget in the schema
|
* An EntityIdValue that we have obtained from a suggest widget in the schema
|
||||||
* alignment dialog.
|
* alignment dialog.
|
||||||
@ -50,26 +52,31 @@ public abstract class SuggestedEntityIdValue implements PrefetchedEntityIdValue
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("id")
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("siteIri")
|
||||||
public String getSiteIri() {
|
public String getSiteIri() {
|
||||||
return _siteIRI;
|
return _siteIRI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("label")
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return _label;
|
return _label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("types")
|
||||||
public List<String> getTypes() {
|
public List<String> getTypes() {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonProperty("iri")
|
||||||
public String getIri() {
|
public String getIri() {
|
||||||
return getSiteIri() + getId();
|
return getSiteIri() + getId();
|
||||||
}
|
}
|
||||||
|
@ -33,15 +33,17 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
public class JacksonSerializationTest {
|
public class JacksonSerializationTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper = new ObjectMapper();
|
private static ObjectMapper mapper = ParsingUtilities.mapper;
|
||||||
|
|
||||||
public static void testSerialize(Object pojo, String expectedJson) {
|
public static void testSerialize(Object pojo, String expectedJson) {
|
||||||
// Test that the pojo is correctly serialized
|
// Test that the pojo is correctly serialized
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String actualJson = mapper.writeValueAsString(pojo);
|
String actualJson = ParsingUtilities.defaultWriter.writeValueAsString(pojo);
|
||||||
assertJsonEquals(expectedJson, actualJson);
|
assertJsonEquals(expectedJson, actualJson);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user