diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/MalformedJsonNotice.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/MalformedJsonNotice.java index 6c4591ad17..c958b2e4d6 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/MalformedJsonNotice.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/MalformedJsonNotice.java @@ -26,7 +26,11 @@ public class MalformedJsonNotice extends ValidationNotice { /** The name of the faulty file. */ private final String filename; - public MalformedJsonNotice(String filename) { + /** The detailed message describing the error. */ + private final String message; + + public MalformedJsonNotice(String filename, String message) { this.filename = filename; + this.message = message; } } diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java index e75482c293..1c81ac3379 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java @@ -30,7 +30,11 @@ public class UnsupportedGeoJsonTypeNotice extends ValidationNotice { /** The value of the unsupported GeoJSON type. */ private final String geoJsonType; - public UnsupportedGeoJsonTypeNotice(String geoJsonType) { + /** The detailed message describing the error. */ + private final String message; + + public UnsupportedGeoJsonTypeNotice(String geoJsonType, String message) { this.geoJsonType = geoJsonType; + this.message = message; } } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java index db9bc81aa4..9e6f4960ff 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java @@ -40,7 +40,8 @@ public GtfsEntityContainer load( List entities = extractFeaturesFromStream(inputStream, noticeContainer); return geoJsonFileDescriptor.createContainerForEntities(entities, noticeContainer); } catch (JsonParseException jpex) { - noticeContainer.addValidationNotice(new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME)); + noticeContainer.addValidationNotice( + new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME, jpex.getMessage())); logger.atSevere().withCause(jpex).log("Malformed JSON in locations.geojson"); return fileDescriptor.createContainerForInvalidStatus(TableStatus.UNPARSABLE_ROWS); } catch (IOException ioex) { @@ -55,6 +56,15 @@ public GtfsEntityContainer load( } } + /** + * Extracts features from the provided GeoJSON input stream. + * + * @param inputStream the input stream containing GeoJSON data + * @param noticeContainer the container to collect validation notices + * @return a list of parsed GeoJSON features + * @throws IOException if an I/O error occurs while reading the input stream + * @throws UnparsableGeoJsonFeatureException if any GeoJSON feature is unparsable + */ public List extractFeaturesFromStream( InputStream inputStream, NoticeContainer noticeContainer) throws IOException, UnparsableGeoJsonFeatureException { @@ -67,7 +77,11 @@ public List extractFeaturesFromStream( throw new UnparsableGeoJsonFeatureException("Missing required field 'type'"); } else if (!jsonObject.get("type").getAsString().equals("FeatureCollection")) { noticeContainer.addValidationNotice( - new UnsupportedGeoJsonTypeNotice(jsonObject.get("type").getAsString())); + new UnsupportedGeoJsonTypeNotice( + jsonObject.get("type").getAsString(), + "Unsupported GeoJSON type: " + + jsonObject.get("type").getAsString() + + ". Use 'FeatureCollection' instead.")); throw new UnparsableGeoJsonFeatureException("Unsupported GeoJSON type"); } JsonArray featuresArray = jsonObject.getAsJsonArray("features");