public void loadProperties(Properties properties) {
    Set<Entry<Object, Object>> entries = properties.entrySet();
    for (Entry entry : entries) {
      String key = (String) entry.getKey();
      Object value = entry.getValue();

      String[] keySplit = key.split("[.]");
      Map<String, Object> target = this;
      for (int i = 0; i < keySplit.length - 1; i++) {
        if (!target.containsKey(keySplit[i])) {
          HashMap subEntry = new HashMap();
          target.put(keySplit[i], subEntry);
          target = subEntry;
        } else {
          Object subEntry = target.get(keySplit[i]);
          if (!(subEntry instanceof Map)) {
            HashMap replace = new HashMap();
            replace.put("_", subEntry);
            target.put(keySplit[i], replace);
          }
          target = (Map<String, Object>) target.get(keySplit[i]);
        }
      }

      if (target.get(keySplit[keySplit.length - 1]) instanceof Map) {
        ((Map) target.get(keySplit[keySplit.length - 1])).put("_", value);
      } else {
        target.put(keySplit[keySplit.length - 1], value);
      }
    }
  }
@Test
  void testLoadPropertyOverrideDict() {
    // given
    K8sSpecTemplate template = new K8sSpecTemplate();
    Properties p = new Properties();
    p.put("k8s.key1", "v2");
    p.put("k8s", "v1");

    // when
    template.loadProperties(p);

    // then
    assertEquals("v1", ((Map) template.get("k8s")).get("_"));
    assertEquals("v2", ((Map) template.get("k8s")).get("key1"));
  }