Skip to content

Commit 80bf73f

Browse files
Small changes
1 parent 9c2e7c5 commit 80bf73f

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

docs/creating-schemas.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ schema.addField(nameField);
2020
Field coordinatesField = new GeopointField("coordinates");
2121
schema.addField(coordinatesField);
2222

23-
System.out.println(schema.getJson());
23+
System.out.println(schema.asJson());
2424

2525
// {"fields":[{"name":"name","format":"default","description":"","type":"string","title":""},{"name":"coordinates","format":"default","description":"","type":"geopoint","title":""}]}
2626
```
@@ -51,7 +51,7 @@ coordinatesFieldJsonObject.put("type", Field.FIELD_TYPE_GEOPOINT);
5151
coordinatesFieldJsonObject.put("format", Field.FIELD_FORMAT_ARRAY);
5252
schema.addField(coordinatesFieldJsonObject);
5353

54-
System.out.println(schema.getJson());
54+
System.out.println(schema.asJson());
5555

5656
/*
5757
{"fields":[
@@ -82,7 +82,7 @@ URL url = new URL("https://raw.githubusercontent.com/frictionlessdata/tableschem
8282
Table table = Table.fromSource(url);
8383

8484
Schema schema = table.inferSchema();
85-
System.out.println(schema.getJson());
85+
System.out.println(schema.asJson());
8686

8787
// {"fields":[{"name":"id","format":"","description":"","title":"","type":"integer","constraints":{}},{"name":"title","format":"","description":"","title":"","type":"string","constraints":{}}]}
8888

@@ -119,7 +119,7 @@ To make sure a schema complies with [Table Schema specifications](https://specs.
119119
JSONObject schemaJsonObj = new JSONObject();
120120
Field nameField = new IntegerField("id");
121121
schemaJsonObj.put("fields", new JSONArray());
122-
schemaJsonObj.getJSONArray("fields").put(nameField.getJson());
122+
schemaJsonObj.asJsonArray("fields").put(nameField.asJson());
123123

124124
Schema schema = Schema.fromJson(schemaJsonObj.toString(), true);
125125

src/main/java/io/frictionlessdata/tableschema/schema/Schema.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void writeJson(File outputFile) throws IOException {
212212

213213
public void writeJson(OutputStream output) throws IOException {
214214
try (BufferedWriter file = new BufferedWriter(new OutputStreamWriter(output))) {
215-
file.write(this.getJson());
215+
file.write(this.asJson());
216216
}
217217
}
218218

@@ -322,8 +322,18 @@ public List<ValidationException> getErrors(){
322322
return this.errors;
323323
}
324324

325+
/**
326+
* For consistency, use {@link #asJson()} instead
327+
* @return JSON-Representation
328+
*/
329+
@Deprecated()
325330
@JsonIgnore
326331
public String getJson() {
332+
return asJson();
333+
}
334+
335+
@JsonIgnore
336+
public String asJson() {
327337
return JsonUtil.getInstance().serialize(this);
328338
}
329339

@@ -412,7 +422,7 @@ public int hashCode() {
412422
*/
413423
@JsonIgnore
414424
public void validate() throws ValidationException{
415-
String json = this.getJson();
425+
String json = this.asJson();
416426
Set<ValidationMessage> messages = tableFormalSchemaValidator.validate(json);
417427
if (!messages.isEmpty()) {
418428
errors.add(new ValidationException(tableFormalSchemaValidator, messages));

src/test/java/io/frictionlessdata/tableschema/DocumentationCases.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void buildASchema() throws Exception{
171171
Field coordinatesField = new GeopointField("coordinates");
172172
schema.addField(coordinatesField);
173173

174-
System.out.println(schema.getJson());
174+
System.out.println(schema.asJson());
175175

176176
/*
177177
{"fields":[
@@ -218,7 +218,7 @@ void buildASchema2() throws Exception{
218218
*/
219219

220220
ObjectMapper objectMapper = new ObjectMapper();
221-
Object jsonObject = objectMapper.readValue(schema.getJson(), Object.class);
221+
Object jsonObject = objectMapper.readValue(schema.asJson(), Object.class);
222222
String expectedString = TestHelper.getResourceFileContent(
223223
"/fixtures/schema/documentation-cases/employee_schema_invalid.json");
224224
assertEquals(objectMapper.readValue(expectedString, Object.class), jsonObject);
@@ -232,7 +232,7 @@ void inferASchema() throws Exception{
232232
Table table = Table.fromSource(url);
233233

234234
Schema schema = table.inferSchema();
235-
System.out.println(schema.getJson());
235+
System.out.println(schema.asJson());
236236

237237
/*
238238
{"fields":[

src/test/java/io/frictionlessdata/tableschema/schema/SchemaInferralTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void inferASchema() throws Exception{
2828
Schema schema = table.inferSchema();
2929

3030
ObjectMapper objectMapper = new ObjectMapper();
31-
Object jsonObject = objectMapper.readValue(schema.getJson(), Object.class);
31+
Object jsonObject = objectMapper.readValue(schema.asJson(), Object.class);
3232
String expectedString = TestHelper.getResourceFileContent(
3333
"/fixtures/schema/employee_schema.json");
3434
assertEquals(objectMapper.readValue(expectedString, Object.class), jsonObject);
@@ -63,7 +63,7 @@ void inferSchemaWithEmptyColumns() throws Exception{
6363

6464
Schema schema = table.inferSchema();
6565

66-
Object jsonObject = objectMapper.readValue(schema.getJson(), Object.class);
66+
Object jsonObject = objectMapper.readValue(schema.asJson(), Object.class);
6767
String expectedString = TestHelper.getResourceFileContent(
6868
"/fixtures/schema/issue-72.json");
6969
assertEquals(objectMapper.readValue(expectedString, Object.class), jsonObject);
@@ -75,7 +75,7 @@ void inferSchemaWithEmptyColumns() throws Exception{
7575

7676
Schema schema2 = table2.inferSchema();
7777

78-
jsonObject = objectMapper.readValue(schema2.getJson(), Object.class);
78+
jsonObject = objectMapper.readValue(schema2.asJson(), Object.class);
7979
assertEquals(objectMapper.readValue(expectedString, Object.class), jsonObject);
8080
Assertions.assertTrue(schema.isValid());
8181
}

src/test/java/io/frictionlessdata/tableschema/schema/SchemaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public void testValidForeignKeyString() throws Exception {
501501
public void testInferTypesComplexSchema() throws Exception {
502502
Table table = Table.fromSource(new File("data/employee_data.csv"), getTestDataDirectory());
503503

504-
String schemaObjStr = table.inferSchema().getJson();
504+
String schemaObjStr = table.inferSchema().asJson();
505505
Schema schema = Schema.fromJson(schemaObjStr, true);
506506

507507
File f = new File(getTestDataDirectory(), "schema/employee_schema.json");
@@ -572,7 +572,7 @@ public void test2Issue20() throws Exception {
572572
Table table = Table.fromSource(url);
573573

574574
Schema schema = table.inferSchema();
575-
String json = schema.getJson();
575+
String json = schema.asJson();
576576
Schema newSchema = Schema.fromJson(json, true);
577577
Assertions.assertTrue(newSchema.isValid());
578578
}

src/test/java/io/frictionlessdata/tableschema/table_tests/TableOtherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void testReadFromValidJSONArrayWithExtendedSchema() throws Exception{
170170
public void testInferTypesIntAndDates() throws Exception{
171171
Table table = Table.fromSource(new File ("dates_data.csv"), getTestDataDirectory());
172172
ObjectMapper objectMapper = new ObjectMapper();
173-
JsonNode schema = objectMapper.readTree(table.inferSchema().getJson());
173+
JsonNode schema = objectMapper.readTree(table.inferSchema().asJson());
174174
JsonNode schemaFiles = schema.get("fields");
175175

176176
// The field names are the same as the name of the type we are expecting to be inferred.

0 commit comments

Comments
 (0)