### Question:
PartitionSpecParser { public static PartitionSpec fromJson(Schema schema, JsonNode json) { Preconditions.checkArgument(json.isObject(), "Cannot parse spec from non-object: %s", json); int specId = JsonUtil.getInt(SPEC_ID, json); PartitionSpec.Builder builder = PartitionSpec.builderFor(schema).withSpecId(specId); buildFromJsonFields(builder, json.get(FIELDS)); return builder.build(); } private  PartitionSpecParser(); static void toJson(PartitionSpec spec, JsonGenerator generator); static String toJson(PartitionSpec spec); static String toJson(PartitionSpec spec, boolean pretty); static PartitionSpec fromJson(Schema schema, JsonNode json); static PartitionSpec fromJson(Schema schema, String json);  }### Answer:
@Test public void testFromJsonWithFieldId() { String specString = "{\n" + " \"spec-id\" : 1,\n" + " \"fields\" : [ {\n" + " \"name\" : \"id_bucket\",\n" + " \"transform\" : \"bucket[8]\",\n" + " \"source-id\" : 1,\n" + " \"field-id\" : 1001\n" + " }, {\n" + " \"name\" : \"data_bucket\",\n" + " \"transform\" : \"bucket[16]\",\n" + " \"source-id\" : 2,\n" + " \"field-id\" : 1000\n" + " } ]\n" + "}"; PartitionSpec spec = PartitionSpecParser.fromJson(table.schema(), specString); Assert.assertEquals(2, spec.fields().size()); Assert.assertEquals(1001, spec.fields().get(0).fieldId()); Assert.assertEquals(1000, spec.fields().get(1).fieldId()); }
@Test public void testFromJsonWithoutFieldId() { String specString = "{\n" + " \"spec-id\" : 1,\n" + " \"fields\" : [ {\n" + " \"name\" : \"id_bucket\",\n" + " \"transform\" : \"bucket[8]\",\n" + " \"source-id\" : 1\n" + " }, {\n" + " \"name\" : \"data_bucket\",\n" + " \"transform\" : \"bucket[16]\",\n" + " \"source-id\" : 2\n" + " } ]\n" + "}"; PartitionSpec spec = PartitionSpecParser.fromJson(table.schema(), specString); Assert.assertEquals(2, spec.fields().size()); Assert.assertEquals(1000, spec.fields().get(0).fieldId()); Assert.assertEquals(1001, spec.fields().get(1).fieldId()); }