forked from D-Net/dnet-hadoop
fixed the deserialization of a json property
This commit is contained in:
parent
2cbf15f4fb
commit
c1e20de7cf
|
@ -12,7 +12,6 @@ import static eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils.structuredProperty;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -175,27 +174,13 @@ public class GenerateRorActionSetJob {
|
||||||
|
|
||||||
for (final Map.Entry<String, ExternalIdType> e : r.getExternalIds().entrySet()) {
|
for (final Map.Entry<String, ExternalIdType> e : r.getExternalIds().entrySet()) {
|
||||||
final String type = e.getKey();
|
final String type = e.getKey();
|
||||||
final Object all = e.getValue().getAll();
|
final List<String> all = e.getValue().getAll();
|
||||||
if (all == null) {
|
if (all != null) {
|
||||||
// skip
|
|
||||||
} else {
|
|
||||||
final Qualifier qualifier = qualifier(
|
final Qualifier qualifier = qualifier(
|
||||||
type, type, ModelConstants.DNET_PID_TYPES, ModelConstants.DNET_PID_TYPES);
|
type, type, ModelConstants.DNET_PID_TYPES, ModelConstants.DNET_PID_TYPES);
|
||||||
if (all instanceof String) {
|
for (final String pid : all) {
|
||||||
pids
|
pids
|
||||||
.add(structuredProperty(all.toString(), qualifier, ROR_DATA_INFO));
|
.add(structuredProperty(pid, qualifier, ROR_DATA_INFO));
|
||||||
} else if (all instanceof Collection) {
|
|
||||||
for (final Object pid : (Collection<?>) all) {
|
|
||||||
pids
|
|
||||||
.add(structuredProperty(pid.toString(), qualifier, ROR_DATA_INFO));
|
|
||||||
}
|
|
||||||
} else if (all instanceof String[]) {
|
|
||||||
for (final String pid : (String[]) all) {
|
|
||||||
pids
|
|
||||||
.add(structuredProperty(pid, qualifier, ROR_DATA_INFO));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("Invalid type for pid list: " + all.getClass());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,32 @@
|
||||||
package eu.dnetlib.dhp.actionmanager.ror.model;
|
package eu.dnetlib.dhp.actionmanager.ror.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
|
||||||
|
@JsonDeserialize(using = ExternalIdTypeDeserializer.class)
|
||||||
public class ExternalIdType implements Serializable {
|
public class ExternalIdType implements Serializable {
|
||||||
|
|
||||||
@JsonProperty("all")
|
private List<String> all;
|
||||||
private Object all;
|
|
||||||
|
|
||||||
@JsonProperty("preferred")
|
|
||||||
private String preferred;
|
private String preferred;
|
||||||
|
|
||||||
private final static long serialVersionUID = 2616688352998387611L;
|
private final static long serialVersionUID = 2616688352998387611L;
|
||||||
|
|
||||||
public Object getAll() {
|
public ExternalIdType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExternalIdType(final List<String> all, final String preferred) {
|
||||||
|
this.all = all;
|
||||||
|
this.preferred = preferred;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAll() {
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAll(final Object all) {
|
public void setAll(final List<String> all) {
|
||||||
this.all = all;
|
this.all = all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
package eu.dnetlib.dhp.actionmanager.ror.model;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.ObjectCodec;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
public class ExternalIdTypeDeserializer extends JsonDeserializer<ExternalIdType> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExternalIdType deserialize(final JsonParser p, final DeserializationContext ctxt)
|
||||||
|
throws IOException, JsonProcessingException {
|
||||||
|
final ObjectCodec oc = p.getCodec();
|
||||||
|
final JsonNode node = oc.readTree(p);
|
||||||
|
|
||||||
|
final JsonNode allNode = node.get("all");
|
||||||
|
|
||||||
|
final String preferred = node.get("preferred").asText();
|
||||||
|
|
||||||
|
final List<String> all = new ArrayList<>();
|
||||||
|
|
||||||
|
if (allNode.isArray()) {
|
||||||
|
allNode.elements().forEachRemaining(x -> all.add(x.asText()));
|
||||||
|
} else {
|
||||||
|
all.add(allNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ExternalIdType(all, preferred);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public class GeonamesCity implements Serializable {
|
||||||
@JsonProperty("nuts_level3")
|
@JsonProperty("nuts_level3")
|
||||||
private NameAndCode nutsLevel3;
|
private NameAndCode nutsLevel3;
|
||||||
|
|
||||||
@JsonProperty("")
|
@JsonProperty("license")
|
||||||
private License license;
|
private License license;
|
||||||
|
|
||||||
private final static long serialVersionUID = -8389480201526252955L;
|
private final static long serialVersionUID = -8389480201526252955L;
|
||||||
|
|
Loading…
Reference in New Issue