use of ai.grakn.engine.controller.response.Attribute in project grakn by graknlabs.
the class JsonConceptBuilder method build.
public static <X extends Concept> X build(String jsonRepresentation) {
Schema.BaseType baseType = Schema.BaseType.valueOf(Json.read(jsonRepresentation).at("base-type").asString());
Concept concept;
try {
switch(baseType) {
case ROLE:
concept = mapper.readValue(jsonRepresentation, Role.class);
break;
case RULE:
concept = mapper.readValue(jsonRepresentation, Rule.class);
break;
case TYPE:
concept = mapper.readValue(jsonRepresentation, MetaConcept.class);
break;
case ENTITY_TYPE:
concept = mapper.readValue(jsonRepresentation, EntityType.class);
break;
case ENTITY:
concept = mapper.readValue(jsonRepresentation, Entity.class);
break;
case ATTRIBUTE_TYPE:
concept = mapper.readValue(jsonRepresentation, AttributeType.class);
break;
case ATTRIBUTE:
concept = mapper.readValue(jsonRepresentation, Attribute.class);
break;
case RELATIONSHIP_TYPE:
concept = mapper.readValue(jsonRepresentation, RelationshipType.class);
break;
case RELATIONSHIP:
concept = mapper.readValue(jsonRepresentation, Relationship.class);
break;
default:
throw new UnsupportedOperationException(String.format("Cannot wrap object of base type {%s}", baseType));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return (X) concept;
}
Aggregations