Fixed serialization of unknown properties

This commit is contained in:
Luca Frosini 2024-04-19 12:11:27 +02:00
parent 8ac4511bde
commit dc8595d13e
2 changed files with 37 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
import org.gcube.com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
import org.gcube.informationsystem.base.reference.AccessType;
@ -32,6 +33,7 @@ import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.Discovery;
import org.gcube.informationsystem.discovery.knowledge.Knowledge;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.slf4j.Logger;
@ -207,6 +209,7 @@ public abstract class ElementMapper {
ArrayNode arrayNode = (ArrayNode) objectNode.get(ModelElement.SUPERTYPES_PROPERTY);
String candidatedSupertype = null;
if(arrayNode!=null) {
for(int i = 0; i < arrayNode.size(); i++) {
String superType = arrayNode.get(i).asText();
if(knownTypes.containsKey(superType)) {
@ -227,6 +230,7 @@ public abstract class ElementMapper {
break;
}
}
}
if(candidatedSupertype!=null) {
if(!objectNode.has(ModelElement.EXPECTED_TYPE_PROPERTY)) {
@ -243,7 +247,17 @@ public abstract class ElementMapper {
}
protected static JsonNode analizeTypes(ObjectNode objectNode) {
String cls = objectNode.get(Element.TYPE_PROPERTY).asText();
String cls = null;
JsonNode typeJN = objectNode.get(Element.TYPE_PROPERTY);
if(typeJN !=null) {
cls = objectNode.get(Element.TYPE_PROPERTY).asText();
}
if(cls==null && objectNode.getNodeType()==JsonNodeType.OBJECT) {
cls = Property.NAME;
}
if(!knownTypes.containsKey(cls)) {
objectNode = setTypeToBestAvailable(objectNode);
}

View File

@ -33,7 +33,11 @@ public class UUIDUtility {
}
public static String getUUIDAsString(JsonNode jsonNode){
return getUUID(jsonNode).toString();
UUID uuid = getUUID(jsonNode);
if(uuid!=null) {
return uuid.toString();
}
return null;
}
public static String getUUIDAsString(String json) throws JsonProcessingException, IOException{