docs: public void write(@NonNull Resource resource) throws IOException {
        try (JsonWriter writer = Json.createWriter(resource)) {
           writer.beginDocument();
           writer.property("id", getId());
           writer.property("content", toString());
  
           if (attributes.size() > 0) {
              writer.beginObject("attributes");
              for (Map.Entry<AttributeType, Val> entry : attributeEntrySet()) {
                 writer.property(entry.getKey().name(), entry.getKey().getValueType().encode(entry.getValue()));
              }
              writer.endObject();
           }
  
           if (annotationSet.size() > 0) {
              writer.beginObject("completed");
              for (AnnotatableType type : getAnnotationSet().getCompleted()) {
                 writer.property(type.canonicalName(), getAnnotationSet().getAnnotationProvider(type));
              }
              writer.endObject();
  
              writer.beginArray("annotations");
              for (Annotation annotation : annotationSet) {
                 writer.beginObject();
                 writer.property("type", annotation.getType().name());
                 writer.property("start", annotation.start());
                 writer.property("end", annotation.end());
                 writer.property("id", annotation.getId());
                 if (Config.get("Annotation.writeContent").asBooleanValue(false)) {
                    writer.property("content", annotation.toString());
                 }
  
                 if (annotation.getAttributeMap().size() > 0) {
                    writer.beginObject("attributes");
                    for (Map.Entry<AttributeType, Val> entry : annotation.attributeEntrySet()) {
                       writer.property(entry.getKey().name(),
                                       entry.getKey().getValueType().encode(entry.getValue()));
  
                    }
                    writer.endObject();
                 }
  
                 Collection<Relation> relations = annotation.relations();
                 if (relations.size() > 0) {
                    writer.beginArray("relations");
                    for (Relation relation : relations) {
                       writer.beginObject();
                       writer.property("type", relation.getType());
                       writer.property("value", relation.getValue());
                       writer.property("target", relation.getTarget());
                       writer.endObject();
                    }
                    writer.endArray();
                 }
  
                 writer.endObject();
              }
              writer.endArray();
           }
           writer.endDocument();
        }
     }