public static String schemaToPdl(DataSchema schema, EncodingStyle encodingStyle)
  {
    StringWriter writer = new StringWriter();

    SchemaToPdlEncoder encoder = new SchemaToPdlEncoder(writer);
    encoder.setEncodingStyle(encodingStyle);

    try
    {
      encoder.encode(schema);
    }
    catch (IOException e)
    {
      throw new IllegalStateException(e);
    }

    return writer.toString();
  }
@Test
  public void testEncodeSortsMultiLevelNestedPropertyMap() throws IOException
  {
    String inputSchema = String.join("\n",
        "@nested = {",
        "  \"b\" : \"b\",",
        "  \"a\" : {",
        "    \"d\" : \"d\",",
        "    \"c\" : \"c\"",
        "  }",
        "}",
        "record A {}");

    DataSchema schema = TestUtil.dataSchemaFromPdlString(inputSchema);

    String indentedSchema = SchemaToPdlEncoder.schemaToPdl(schema, SchemaToPdlEncoder.EncodingStyle.INDENTED);

    assertEquals(String.join("\n",
        "@nested = {",
        "  \"a\" : {",
        "    \"c\" : \"c\",",
        "    \"d\" : \"d\"",
        "  },",
        "  \"b\" : \"b\"",
        "}",
        "record A {}"), indentedSchema);

    String compactSchema = SchemaToPdlEncoder.schemaToPdl(schema, SchemaToPdlEncoder.EncodingStyle.COMPACT);

    assertEquals("@nested={\"a\":{\"c\":\"c\",\"d\":\"d\"},\"b\":\"b\"}record A{}", compactSchema);
  }