Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null value parsing #13

Closed
SangI762 opened this issue Oct 21, 2019 · 2 comments
Closed

Null value parsing #13

SangI762 opened this issue Oct 21, 2019 · 2 comments

Comments

@SangI762
Copy link

Hey, I have tried library, it's awesome, but I have an issue with null value.

I have created my Dto object which has several GeoJson properties:

public class ParkingZoneDto
 {
        [JsonProperty]
        public int Id { get; set; }

        [JsonProperty]
        public string Name { get; set; }

        [JsonProperty]
        public GeoJson GeographyPolygons { get; set; }

        [JsonProperty]
        public GeoJson PinPositions { get; set; }
}

And JsonConvert.DeserializeObject failing when in the response property PinPossitions is null (some times here should be MultiPoint) :

{
    ...,
    "PinPositions": null,
    ...
}

Error is: Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: Null. Path '[0].PinPositions', line 1, position 41. at Newtonsoft.Json.Linq.JObject.Load (Newtonsoft.Json.JsonReader reader,...

If I removed that property from my response string, then deserialization success and PinPositions property in my dto is null. So I hoping that this case should be covered by library: don't try parse null value into GeoJson object.

Am I missing something? Maybe is better workaround than removing properties from content string before desereliazation? thanks in advance.

@hakenmt
Copy link
Contributor

hakenmt commented Oct 21, 2019

I think this is doable, I'm just not sure it follows the RFC:

A GeoJSON object represents a Geometry, Feature, or collection of Features.

o A GeoJSON object is a JSON object.
o A GeoJSON object has a member with the name "type". The value of the member MUST be one of the GeoJSON types.
o A GeoJSON object MAY have a "bbox" member, the value of which MUST be a bounding box array (see Section 5).
o A GeoJSON object MAY have other members (see Section 6).

I'm open to interpretation and suggestions, do you believe the RFC allows for a GeoJSON object to be null? Or is it trivial?

@SangI762
Copy link
Author

It’s only model and business logic. I think it’s not related with RFC. I just want nullable (optional) property of GeoJson. It should have strong structure when content exist, but null is null, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants