public static <T extends JsonTemplate> T readJsonFromFileWithLock(
      Path jsonFile, Class<T> templateClass) throws IOException {
    // channel is closed by inputStream.close()
    FileChannel channel = FileChannel.open(jsonFile, StandardOpenOption.READ);
    channel.lock(0, Long.MAX_VALUE, true); // shared lock, released by channel close
    try (InputStream inputStream = Channels.newInputStream(channel)) {
      return objectMapper.readValue(inputStream, templateClass);
    }
  }
Deserializes a JSON file via a JSON object template with a shared lock on the file.

@param <T> child type of {@link JsonTemplate}
@param jsonFile a file containing a JSON string
@param templateClass the template to deserialize the string to
@return the template filled with the values parsed from {@code jsonFile}
@throws IOException if an error occurred during reading the file or parsing the JSON
jib-core/src/main/java/com/google/cloud/tools/jib/json/JsonTemplateMapper.java