PdlBuilder writeProperties(List<String> prefix, Map<String, Object> properties) throws IOException
  {
    List<Map.Entry<String, Object>> orderedProperties =  properties.entrySet().stream()
        .sorted(Map.Entry.comparingByKey())
        .collect(Collectors.toList());
    for (Map.Entry<String, Object> entry : orderedProperties)
    {
      String key = entry.getKey();
      Object value = entry.getValue();

      // Copy the prefix path segments and append the current segment
      ArrayList<String> pathParts = new ArrayList<>(prefix);
      pathParts.add(key);

      if (value instanceof DataMap)
      {
        DataMap dm = (DataMap) value;
        // Decide encoding style based on map branches/size
        if (dm.size() == 1)
        {
          // encode value property like @x.y.z = "value"
          writeProperties(pathParts, dm);
        }
        else
        {
          // encode value property like @x = { "y": { "z": "value" } }
          writeProperty(pathParts, dm);
        }
      }
      else if (Boolean.TRUE.equals(value))
      {
        // Use shorthand for boolean true.  Instead of writing "@deprecated = true",
        // write "@deprecated".
        indent().write("@").writePath(pathParts).newline();
      }
      else
      {
        writeProperty(pathParts, value);
      }
    }
    return this;
  }
@Test(dataProvider = "propertiesMapProvider")
  public void testWriteProperties(Map<String, Object> properties,
                                  String indentPdlString,
                                  String compactPdlString) throws IOException
  {
    StringWriter indentWriter = new StringWriter();
    PdlBuilder indentPdlBuilder = (new IndentedPdlBuilder.Provider()).newInstance(indentWriter);
    indentPdlBuilder.writeProperties(Collections.emptyList(), properties);

    StringWriter compactWriter = new StringWriter();
    PdlBuilder compactPdlBuilder = (new CompactPdlBuilder.Provider()).newInstance(compactWriter);
    compactPdlBuilder.writeProperties(Collections.emptyList(), properties);

    Assert.assertEquals(indentPdlString, indentWriter.toString());
    Assert.assertEquals(compactPdlString, compactWriter.toString());
  }