!7 extend BEAObject { S _originalStruct; } sclass CRef { long id; S gid; } module BEAThoughtBot1 > DynCRUD { switchable S user; switchable S botToken; start { //crud.unshownFields = litset("_originalStruct"); } void importAll { Map data = cast postJSONPage("https://bea.gazelle.rocks/bot/beaList", _user := user, _botToken := botToken); L list = cast data.get("result"); if (list == null) ret with infoBox(str(data.get("error"))); new L objects; for (Map map : list) { //long id = toLong(map.get("id")); GlobalID globalID = GlobalID((S) map.get("gid")); S struct = cast map.get("struct"); BEAObject o = uniq BEAObject(+globalID); objects.add(o); cset(o, _originalStruct := struct); } unpackImportedStructures(objects); } void unpackImportedStructures(Cl l) { fOr (BEAObject o : l) try { S struct = o._originalStruct; continue if empty(struct); cclearAllDynamicFields(o); // make markers explicit so we can modify the token count LS tok = javaTokForStructure(structure_convertTokenMarkersToExplicit(struct)); // resolve concept references jreplace(tok, "CRef(id=)", "null"); jreplace_dyn(tok, "CRef(gid=)", (_tok, cIdx) -> uniq BEAObject(globalID := unquote(_tok.get(cIdx+8)))); struct = join(tok); print(struct); //O data = safeUnstructureAllowingCertainClasses(struct, "CRef"); } catch print e { cset(o, _errorUnpacking := getStackTrace(e)); } } }