forked from D-Net/dnet-hadoop
44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
|
|
package eu.dnetlib.dhp.rdfconverter.utils;
|
|
|
|
import java.io.IOException;
|
|
|
|
import com.fasterxml.jackson.core.JsonParser;
|
|
import com.fasterxml.jackson.core.ObjectCodec;
|
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
|
|
|
import eu.dnetlib.dhp.rdfconverter.bioschema.model.BioSchemaProtein;
|
|
|
|
public class CustomPropertyValueDeserializer
|
|
extends StdDeserializer<BioSchemaProtein.Link> {
|
|
|
|
public CustomPropertyValueDeserializer() {
|
|
this(null);
|
|
}
|
|
|
|
public CustomPropertyValueDeserializer(Class<?> vc) {
|
|
super(vc);
|
|
}
|
|
|
|
@Override
|
|
public BioSchemaProtein.Link deserialize(
|
|
JsonParser jsonparser, DeserializationContext context)
|
|
throws IOException {
|
|
ObjectCodec oc = jsonparser.getCodec();
|
|
JsonNode node = oc.readTree(jsonparser);
|
|
JsonNode id = node.get("@id");
|
|
if (id != null) {
|
|
BioSchemaProtein.Link link = new BioSchemaProtein.Link();
|
|
link.setId(id.asText());
|
|
return link;
|
|
} else {
|
|
String txt = node.asText();
|
|
BioSchemaProtein.Link link = new BioSchemaProtein.Link();
|
|
link.setId(txt);
|
|
return link;
|
|
}
|
|
}
|
|
}
|