Skip to content

Commit 54a572a

Browse files
authored
feat: 1927 flex geo json parsing failed (#1947)
1 parent 2fa6883 commit 54a572a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

core/src/main/java/org/mobilitydata/gtfsvalidator/notice/MalformedJsonNotice.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public class MalformedJsonNotice extends ValidationNotice {
2626
/** The name of the faulty file. */
2727
private final String filename;
2828

29-
public MalformedJsonNotice(String filename) {
29+
/** The detailed message describing the error. */
30+
private final String message;
31+
32+
public MalformedJsonNotice(String filename, String message) {
3033
this.filename = filename;
34+
this.message = message;
3135
}
3236
}

core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public class UnsupportedGeoJsonTypeNotice extends ValidationNotice {
3030
/** The value of the unsupported GeoJSON type. */
3131
private final String geoJsonType;
3232

33-
public UnsupportedGeoJsonTypeNotice(String geoJsonType) {
33+
/** The detailed message describing the error. */
34+
private final String message;
35+
36+
public UnsupportedGeoJsonTypeNotice(String geoJsonType, String message) {
3437
this.geoJsonType = geoJsonType;
38+
this.message = message;
3539
}
3640
}

main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public GtfsEntityContainer load(
4040
List<GtfsGeoJsonFeature> entities = extractFeaturesFromStream(inputStream, noticeContainer);
4141
return geoJsonFileDescriptor.createContainerForEntities(entities, noticeContainer);
4242
} catch (JsonParseException jpex) {
43-
noticeContainer.addValidationNotice(new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME));
43+
noticeContainer.addValidationNotice(
44+
new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME, jpex.getMessage()));
4445
logger.atSevere().withCause(jpex).log("Malformed JSON in locations.geojson");
4546
return fileDescriptor.createContainerForInvalidStatus(TableStatus.UNPARSABLE_ROWS);
4647
} catch (IOException ioex) {
@@ -55,6 +56,15 @@ public GtfsEntityContainer load(
5556
}
5657
}
5758

59+
/**
60+
* Extracts features from the provided GeoJSON input stream.
61+
*
62+
* @param inputStream the input stream containing GeoJSON data
63+
* @param noticeContainer the container to collect validation notices
64+
* @return a list of parsed GeoJSON features
65+
* @throws IOException if an I/O error occurs while reading the input stream
66+
* @throws UnparsableGeoJsonFeatureException if any GeoJSON feature is unparsable
67+
*/
5868
public List<GtfsGeoJsonFeature> extractFeaturesFromStream(
5969
InputStream inputStream, NoticeContainer noticeContainer)
6070
throws IOException, UnparsableGeoJsonFeatureException {
@@ -67,7 +77,11 @@ public List<GtfsGeoJsonFeature> extractFeaturesFromStream(
6777
throw new UnparsableGeoJsonFeatureException("Missing required field 'type'");
6878
} else if (!jsonObject.get("type").getAsString().equals("FeatureCollection")) {
6979
noticeContainer.addValidationNotice(
70-
new UnsupportedGeoJsonTypeNotice(jsonObject.get("type").getAsString()));
80+
new UnsupportedGeoJsonTypeNotice(
81+
jsonObject.get("type").getAsString(),
82+
"Unsupported GeoJSON type: "
83+
+ jsonObject.get("type").getAsString()
84+
+ ". Use 'FeatureCollection' instead."));
7185
throw new UnparsableGeoJsonFeatureException("Unsupported GeoJSON type");
7286
}
7387
JsonArray featuresArray = jsonObject.getAsJsonArray("features");

0 commit comments

Comments
 (0)