Commit d37d3897 authored by Johannes Mey's avatar Johannes Mey
Browse files

add more checks during serialization

parent cceb9033
......@@ -118,6 +118,15 @@ aspect ComponentAnalysis {
// TODO
return true;
}
syn boolean Component.isList() = false;
eq ListComponent.isList() = true;
syn boolean Component.isOpt() = false;
eq OptComponent.isOpt() = true;
syn boolean Component.isNullable() = false;
eq TokenComponent.isNullable() = !"float double int short long char byte boolean".contains(getTypeUse().getID());
}
aspect InstanceSupplier {
......
......@@ -1051,10 +1051,20 @@ aspect Serializer {
sb.append(ind(4) + "g.writeObjectFieldStart(fieldName);\n");
sb.append(ind(3) + "}\n");
sb.append(ind(3) + "g.writeStringField(\"" + jsonTypeKey + "\", \"" + getID() + "\");\n");
sb.append(ind(3) + "if (__uid() == null) throw new SerializationException(\"The unique identifier of " + getID() + " is missing.\");\n");
sb.append(ind(3) + "g.writeStringField(\"id\", __uid());\n");
if (componentsTransitive().size() > 0) {
sb.append(ind(3) + "g.writeObjectFieldStart(\"children\");\n");
for (Component child : componentsTransitive()) {
if (child.isNullable()) {
String componentAccessor = child.getID();
if (child.isList()) {
componentAccessor += "List";
} else if (child.isOpt()) {
componentAccessor += "Opt";
}
sb.append(ind(3) + "if (get" + componentAccessor + "() == null) throw new SerializationException(\"The component " + child.getID() + " of " + getID() + " is missing.\");\n");
}
child.serialize(sb, 3);
}
sb.append(ind(3) + "g.writeEndObject(); // children\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment