1
0
Fork 0

fixed the deserialization of a json property

This commit is contained in:
Michele Artini 2021-05-18 14:00:14 +02:00
parent 2cbf15f4fb
commit c1e20de7cf
4 changed files with 57 additions and 26 deletions

View File

@ -12,7 +12,6 @@ import static eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils.structuredProperty;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
@ -175,27 +174,13 @@ public class GenerateRorActionSetJob {
for (final Map.Entry<String, ExternalIdType> e : r.getExternalIds().entrySet()) {
final String type = e.getKey();
final Object all = e.getValue().getAll();
if (all == null) {
// skip
} else {
final List<String> all = e.getValue().getAll();
if (all != null) {
final Qualifier qualifier = qualifier(
type, type, ModelConstants.DNET_PID_TYPES, ModelConstants.DNET_PID_TYPES);
if (all instanceof String) {
for (final String pid : all) {
pids
.add(structuredProperty(all.toString(), 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());
.add(structuredProperty(pid, qualifier, ROR_DATA_INFO));
}
}
}

View File

@ -2,24 +2,32 @@
package eu.dnetlib.dhp.actionmanager.ror.model;
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 {
@JsonProperty("all")
private Object all;
private List<String> all;
@JsonProperty("preferred")
private String preferred;
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;
}
public void setAll(final Object all) {
public void setAll(final List<String> all) {
this.all = all;
}

View File

@ -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);
}
}

View File

@ -28,7 +28,7 @@ public class GeonamesCity implements Serializable {
@JsonProperty("nuts_level3")
private NameAndCode nutsLevel3;
@JsonProperty("")
@JsonProperty("license")
private License license;
private final static long serialVersionUID = -8389480201526252955L;