code: @Override
    public <T> T remove(Object objectToRemove, String collectionName) {
      if (null == objectToRemove) {
        throw new InvalidJsonDbApiUsageException("Null Object cannot be removed from DB");
      }
      Util.ensureNotRestricted(objectToRemove);
  
      CollectionMetaData collectionMeta = cmdMap.get(collectionName);
      collectionMeta.getCollectionLock().writeLock().lock();
      try {
        @SuppressWarnings("unchecked")
        Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName);
        if (null == collection) {
          throw new InvalidJsonDbApiUsageException("Collection by name '" + collectionName + "' not found. Create collection first.");
        }
  
        CollectionMetaData cmd = cmdMap.get(collectionName);
        Object id = Util.getIdForEntity(objectToRemove, cmd.getIdAnnotatedFieldGetterMethod());
        if (!collection.containsKey(id)) {
          throw new InvalidJsonDbApiUsageException(String.format("Objects with Id %s not found in collection %s", id, collectionName));
        }
  
        JsonWriter jw;
        try {
          jw = new JsonWriter(dbConfig, cmd, collectionName, fileObjectsRef.get().get(collectionName));
        } catch (IOException ioe) {
          logger.error("Failed to obtain writer for " + collectionName, ioe);
          throw new JsonDBException("Failed to save " + collectionName, ioe);
        }
        boolean substractResult = jw.removeFromJsonFile(collection, id);
        if(substractResult) {
          T objectRemoved = collection.remove(id);
          // Don't need to clone it, this object no more exists in the collection
          return objectRemoved;
        } else {
          return null;
        }
      } finally {
        collectionMeta.getCollectionLock().writeLock().unlock();
      }
    }
docs: /* (non-Javadoc)
  @see org.jsondb.JsonDBOperations#remove(java.lang.Object, java.lang.String)