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 testEncodeDefaultValueFieldsInSchemaOrder() throws IOException
  {
    String inputSchema = String.join("\n",
        "record A {",
        "",
        "  b: record B {",
        "    b1: string",
        "",
        "    c: record C {",
        "      c2: int",
        "      c1: boolean",
        "",
        "      c3: array[string]",
        "    }",
        "    b2: double",
        "  } = {",
        "    \"b1\" : \"hello\",",
        "    \"b2\" : 0.05,",
        "    \"c\" : {",
        "      \"c1\" : true,",
        "      \"c2\" : 100,",
        "      \"c3\" : [ \"one\", \"two\" ]",
        "    }",
        "  }",
        "}");

    DataSchema schema = TestUtil.dataSchemaFromPdlString(inputSchema);

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

    assertEquals(String.join("\n",
        "record A {",
        "",
        "  b: record B {",
        "    b1: string",
        "",
        "    c: record C {",
        "      c2: int",
        "      c1: boolean",
        "",
        "      c3: array[string]",
        "    }",
        "    b2: double",
        "  } = {",
        "    \"b1\" : \"hello\",",
        "    \"c\" : {",
        "      \"c2\" : 100,",
        "      \"c1\" : true,",
        "      \"c3\" : [ \"one\", \"two\" ]",
        "    },",
        "    \"b2\" : 0.05",
        "  }",
        "}"), indentedSchema);

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

    assertEquals(Stream.of(
        "record A{",
        "  b:record B{",
        "    b1:string,",
        "    c:record C{",
        "    c2:int,",
        "    c1:boolean,",
        "    c3:array[string]",
        "  }",
        "  b2:double",
        "  }={",
        "    \"b1\":\"hello\",",
        "    \"c\":{",
        "      \"c2\":100,",
        "      \"c1\":true,",
        "      \"c3\":[\"one\",\"two\"]",
        "    },",
        "    \"b2\":0.05",
        "  }",
        "}")
        .map(String::trim)
        .collect(Collectors.joining()), compactSchema);
  }