Skip to content

Commit

Permalink
deserialization: avoid null values on generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiedentop committed Feb 29, 2024
1 parent a788b56 commit 793b07d
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 48 deletions.
15 changes: 8 additions & 7 deletions lib/src/geojson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ abstract class GeometryType<T> extends GeometryObject {
}

/// Point, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.2
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class Point extends GeometryType<Position> {
Point({BBox? bbox, required Position coordinates})
: super.withType(coordinates, GeoJSONObjectType.point, bbox: bbox);
Expand All @@ -460,7 +460,7 @@ class Point extends GeometryType<Position> {
}

/// MultiPoint, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.3
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class MultiPoint extends GeometryType<List<Position>> {
MultiPoint({BBox? bbox, List<Position> coordinates = const []})
: super.withType(coordinates, GeoJSONObjectType.multiPoint, bbox: bbox);
Expand All @@ -485,7 +485,7 @@ class MultiPoint extends GeometryType<List<Position>> {
}

/// LineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.4
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class LineString extends GeometryType<List<Position>> {
LineString({BBox? bbox, List<Position> coordinates = const []})
: super.withType(coordinates, GeoJSONObjectType.lineString, bbox: bbox);
Expand All @@ -509,7 +509,7 @@ class LineString extends GeometryType<List<Position>> {
}

/// MultiLineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.5
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class MultiLineString extends GeometryType<List<List<Position>>> {
MultiLineString({BBox? bbox, List<List<Position>> coordinates = const []})
: super.withType(coordinates, GeoJSONObjectType.multiLineString,
Expand Down Expand Up @@ -538,7 +538,7 @@ class MultiLineString extends GeometryType<List<List<Position>>> {
}

/// Polygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.6
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class Polygon extends GeometryType<List<List<Position>>> {
Polygon({BBox? bbox, List<List<Position>> coordinates = const []})
: super.withType(coordinates, GeoJSONObjectType.polygon, bbox: bbox);
Expand All @@ -565,7 +565,7 @@ class Polygon extends GeometryType<List<List<Position>>> {
}

/// MultiPolygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.7
@JsonSerializable(explicitToJson: true)
@JsonSerializable(explicitToJson: true, includeIfNull: false)
class MultiPolygon extends GeometryType<List<List<List<Position>>>> {
MultiPolygon({BBox? bbox, List<List<List<Position>>> coordinates = const []})
: super.withType(coordinates, GeoJSONObjectType.multiPolygon, bbox: bbox);
Expand All @@ -592,7 +592,8 @@ class MultiPolygon extends GeometryType<List<List<List<Position>>>> {
}

/// GeometryCollection, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.8
@JsonSerializable(explicitToJson: true, createFactory: false)
@JsonSerializable(
explicitToJson: true, createFactory: false, includeIfNull: false)
class GeometryCollection extends GeometryObject {
List<GeometryType> geometries;

Expand Down
141 changes: 100 additions & 41 deletions lib/src/geojson.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 793b07d

Please sign in to comment.