Skip to content

Commit

Permalink
clarify why unknown field names are tolerated
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Oct 3, 2024
1 parent ecc8002 commit e4614bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ private Bundle create (Request req, Response res) {
bundle.totalFeeds = bundleWithFeed.totalFeeds;
}
if (files.get("config") != null) {
// For validation, rather than reading as freeform JSON, deserialize into a model class instance.
// However, only the instance fields specifying things other than OSM and GTFS IDs will be retained.
// Validation by deserializing into a model class instance. Unknown fields are ignored to
// allow sending config to custom or experimental workers with features unknown to the backend.
// The fields specifying OSM and GTFS IDs are not expected here. They will be ignored and overwritten.
String configString = files.get("config").get(0).getString();
bundle.config = JsonUtil.objectMapper.readValue(configString, TransportNetworkConfig.class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/conveyal/analysis/models/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Bundle extends Model implements Cloneable {
public int feedsComplete;
public int totalFeeds;

// The definitive TransportNetworkConfig is a JSON file stored alonside the feeds in file storage. It is
// The definitive TransportNetworkConfig is a JSON file stored alongside the feeds in file storage. It is
// duplicated here to record any additional user-specified options that were supplied when the bundle was created.
// It may contain redundant copies of information stored in the outer level Bundle such as OSM and GTFS feed IDs.
public TransportNetworkConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ private TransportNetworkConfig loadNetworkConfig (String networkId) {
File configFile = fileStorage.getFile(configFileKey);
try {
// Use lenient mapper to mimic behavior in objectFromRequestBody.
// A single network configuration file might be used across several worker versions. Unknown field names
// may be present for other worker versions unknown to this one. So we can't strictly validate field names.
return JsonUtilities.lenientObjectMapper.readValue(configFile, TransportNetworkConfig.class);
} catch (IOException e) {
throw new RuntimeException("Error reading TransportNetworkConfig. Does it contain new unrecognized fields?", e);
Expand Down

0 comments on commit e4614bb

Please sign in to comment.