You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a Feature has a commonly used identifier, that identifier
SHOULD be included as a member of the Feature object with the name
"id", and the value of this member is either a JSON string or
number.
However, current implementation only supports deserialization of string values for this field.
Proposed solutions:
A custom JSON converter for this field, with storing the value as a string.
Storing the value as a discriminated union of string and int (or long).
Hi @dmitry-kandiner thanks for reporting this. I think the latter option is good, but is not in the language yet (please advise if I'm wrong).
I might have also a proposal: make the Feature generic (like Feature : Feature) where the Id field type could be specified. That's good when you know what you expect.
Other (ugly but OK type-wise) idea : let the Feature's Id property be an object and support deserialization from numeric of string.
You are right, the discriminated union type is not supported by the language yet, but it can be implemented for this specific need as an internal class for this project.
Making the Feature class a generic could be fine, but then an array of Features will be limited to a single specification only.
Letting the Id be an object is the easiest way to implement it, but it will require validation during deserialization and an explicit cast when the field is accessed.
You are right, the discriminated union type is not supported by the language yet, but it can be implemented for this specific need as an internal class for this project.
I wonder how that could be possible. Can you elaborate?
Making the Feature class a generic could be fine, but then an array of Features will be limited to a single specification only.
Yes you are right!
Letting the Id be an object is the easiest way to implement it, but it will require validation during deserialization and an explicit cast when the field is accessed.
Yes that's a bit old school I don't like it either.
I made some basic checks for this code - used it as a type of Feature<TGeometry, TProps>._id. It passes the unit tests you have (not tested with numeric values yet).
What do you think?
Activity
xfischer commentedon Aug 6, 2025
Hi @dmitry-kandiner thanks for reporting this. I think the latter option is good, but is not in the language yet (please advise if I'm wrong).
I might have also a proposal: make the Feature generic (like Feature : Feature) where the Id field type could be specified. That's good when you know what you expect.
Other (ugly but OK type-wise) idea : let the Feature's Id property be an object and support deserialization from numeric of string.
dmitry-kandiner commentedon Aug 6, 2025
Hello @xfischer !
You are right, the discriminated union type is not supported by the language yet, but it can be implemented for this specific need as an internal class for this project.
Making the
Featureclass a generic could be fine, but then an array ofFeatures will be limited to a single specification only.Letting the Id be an
objectis the easiest way to implement it, but it will require validation during deserialization and an explicit cast when the field is accessed.xfischer commentedon Aug 6, 2025
I wonder how that could be possible. Can you elaborate?
Yes you are right!
Yes that's a bit old school I don't like it either.
dmitry-kandiner commentedon Aug 6, 2025
Consider this code snippet:
I made some basic checks for this code - used it as a type of
Feature<TGeometry, TProps>._id. It passes the unit tests you have (not tested with numeric values yet).What do you think?
Added support for numeric Feature.Id values (Issue GeoJSON-Net#35)