Would it be possible to default the type
fields?
#158
Replies: 2 comments
-
This topic has been discussed multiple times already: I'm sorry it makes things Taking your example 👇 will work, while this is not a valid Point Geometry object
|
Beta Was this translation helpful? Give feedback.
-
I tried to cover this example in the last paragraph, especially the last bullet point. From my experience the vast majority of use cases parses GeoJSON on a higher level like Note that the example we are talking about is very rare, because:
On the other hand, the repetitiveness in the construction is rather pervasive, and is something that jumps into the face of every developer working with the library (triggering e.g. discussions in code reviews about the ugliness of the code). Therefore, it would be a case where I'd trade-off ergonomics in favor of catering for the needs of a rare use case, especially since the resulting set of accepted GeoJSON is basically a superset of the specs. |
Beta Was this translation helpful? Give feedback.
-
Currently the construction of the geometry types is a bit verbose and non-DRY, because for each type it is necessary to specify the
type
discriminator in the code. I.e., the construction looks like this:Point(type="Point", ...)
MultiPoint(type="MultiPoint", ...)
Having to specify the type make these expressions very long and the
type
field just repeats an information that is basically expressed by the type (i.e. class) already.Would you be fine with introducing defaults for these
Literal
s? This would greatly simplify the construction, and since theGeometry
type declares thetype
field as a discriminator for the union, it is still mandatory for the parsing as desired. To demonstrate in a minified example:The only behavior that would change is that it would now in principle be possible to parse either a
Point
orMultiPoint
from a data structure without atype
field. But I think this is fine because:type
field, i.e., this case cannot occur for proper GeoJSON.Point
from such "broken" GeoJSON it may be fine if the parsing succeeds as long as the rest of the data payload fits. Note that this will also only allow parsing specific types likePoint
,MultiPoint
, ... but not a generalGeometry
(because it needs the discriminator), so such cases seem rather pathological.Beta Was this translation helpful? Give feedback.
All reactions