Reorganizing json

This commit is contained in:
Luca Frosini 2023-04-27 14:46:08 +02:00
parent 10563e6b02
commit ad6018d5fb
4 changed files with 10 additions and 11 deletions

View File

@ -2,6 +2,9 @@ package org.gcube.informationsystem.base.reference;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.informationsystem.model.reference.properties.Metadata;
/**
@ -9,17 +12,22 @@ import org.gcube.informationsystem.model.reference.properties.Metadata;
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonPropertyOrder({ Element.TYPE_PROPERTY, Element.SUPERTYPES_PROPERTY, IdentifiableElement.UUID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
public interface IdentifiableElement extends Element {
public static final String UUID_PROPERTY = "uuid";
public static final String METADATA_PROPERTY = "metadata";
@JsonGetter(value = UUID_PROPERTY)
public UUID getUUID();
@JsonSetter(value = UUID_PROPERTY)
public void setUUID(UUID uuid);
@JsonGetter(value = METADATA_PROPERTY)
public Metadata getMetadata();
@JsonSetter(value = METADATA_PROPERTY)
public void setMetadata(Metadata metadata);
}

View File

@ -2,9 +2,7 @@ package org.gcube.informationsystem.base.reference.entities;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Metadata;
@ -26,21 +24,17 @@ public interface EntityElement extends Element, IdentifiableElement {
public static final String NAME = "EntityElement"; //Entity.class.getSimpleName();
@JsonGetter(value = UUID_PROPERTY)
@ISProperty(name = UUID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
@Override
public UUID getUUID();
@JsonSetter(value = UUID_PROPERTY)
@Override
public void setUUID(UUID uuid);
@JsonGetter(value = METADATA_PROPERTY)
@ISProperty(name=METADATA_PROPERTY, mandatory=true, nullable=false, description="Metadata associated with the instance that is automatically created/updated by the system.")
@Override
public Metadata getMetadata();
@JsonSetter(value = METADATA_PROPERTY)
@Override
public void setMetadata(Metadata metadata);

View File

@ -4,7 +4,6 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
@ -29,21 +28,17 @@ public interface RelationElement<S extends EntityElement, T extends EntityElemen
public static final String SOURCE_PROPERTY = "source";
public static final String TARGET_PROPERTY = "target";
@JsonGetter(value = UUID_PROPERTY)
@ISProperty(name = UUID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
@Override
public UUID getUUID();
@JsonSetter(value = UUID_PROPERTY)
@Override
public void setUUID(UUID uuid);
@JsonGetter(value = METADATA_PROPERTY)
@ISProperty(name=METADATA_PROPERTY, mandatory=true, nullable=false, description="Metadata associated with the instance that is automatically created/updated by the system.")
@Override
public Metadata getMetadata();
@JsonSetter(value = METADATA_PROPERTY)
@Override
public void setMetadata(Metadata metadata);

View File

@ -22,6 +22,7 @@ import org.gcube.com.fasterxml.jackson.databind.JavaType;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
import org.gcube.com.fasterxml.jackson.databind.module.SimpleModule;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
@ -58,6 +59,7 @@ public abstract class ElementMapper {
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.getSerializationConfig().with(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
/*
* Instructing Jackson to serialize any Date in the defined pattern