public <T extends RootEntity> void write(T entity, Callback cb) {
   if (entity == null) return;
   ModelType type = ModelType.forModelClass(entity.getClass());
   if (type == null || entity.getRefId() == null) {
     warn(cb, "no refId, or type is unknown", entity);
     return;
   }
   if (conf.hasVisited(type, entity.getId())) return;
   Writer<T> writer = getWriter(entity, conf);
   if (writer == null) {
     warn(cb, "no writer found for type " + type, entity);
     return;
   }
   try {
     conf.refFn =
         ref -> {
           write(ref, cb);
         };
     JsonObject obj = writer.write(entity);
     conf.store.put(type, obj);
     if (writer.isExportExternalFiles()) writeExternalFiles(entity, type, cb);
     if (cb != null) cb.apply(Message.info("data set exported"), entity);
   } catch (Exception e) {
     e.printStackTrace();
     if (cb != null) cb.apply(Message.error("failed to export data set", e), entity);
   }
 }
 public JsonExport(IDatabase database, EntityStore store) {
   conf = ExportConfig.create(database, store);
 }
 public void setExportDefaultProviders(boolean value) {
   conf.exportProviders = value;
 }
 public void setExportReferences(boolean value) {
   conf.exportReferences = value;
 }
 public static <T extends RootEntity> JsonObject toJson(T entity) {
   if (entity == null) return new JsonObject();
   Writer<T> writer = getWriter(entity, ExportConfig.create());
   return writer.write(entity);
 }