@Override public void removeAttribute(String name) { attributeMap.remove(name); }
/** * Remove a field from JSON. Has no effect if the JSON if not object types or if the given field doesn't exists. * * @param json JSON object * @param fieldName Name of the field to remove */ public static void remove(BValue json, String fieldName) { if (json == null || json.getType().getTag() != TypeTags.JSON_TAG) { return; } ((BMap<String, ?>) json).remove(fieldName); }
public void execute(Context ctx) { BMap<String, BValue> map = (BMap<String, BValue>) ctx.getRefArgument(0); try { boolean isRemoved = map.remove(ctx.getStringArgument(0)); ctx.setReturnValues(new BBoolean(isRemoved)); } catch (BLangFreezeException e) { throw new BallerinaException(e.getMessage(), "Failed to remove element from map: " + e.getDetail()); } } }
/** * Walk the object graph and remove the HASH code from nodes that does not repeat. * * @param jsonObj BValue tree to be trimmed. * @param repeatedReferenceSet Set of hashCodes of repeated references. */ @SuppressWarnings("unchecked") static void trimTree(BValue jsonObj, Set<Long> repeatedReferenceSet) { if (jsonObj == null) { return; } if (jsonObj instanceof BMap) { BMap map = (BMap) jsonObj; BInteger objId = (BInteger) map.get(JsonSerializerConst.ID_TAG); if (objId != null && !repeatedReferenceSet.contains(objId.intValue())) { map.remove(JsonSerializerConst.ID_TAG); } trimTree(map.get(JsonSerializerConst.VALUE_TAG), repeatedReferenceSet); } if (jsonObj instanceof BValueArray) { BValueArray array = (BValueArray) jsonObj; for (int i = 0; i < array.size(); i++) { trimTree(array.getRefValue(i), repeatedReferenceSet); } } } }