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

JsonSerializationException: 'Required property 'properties' not found in JSON #131

Closed
tuyen-vuduc opened this issue Sep 21, 2019 · 7 comments

Comments

@tuyen-vuduc
Copy link

Hi,

Please allow Properties property to be nullable in JSON.

Newtonsoft.Json.JsonSerializationException: 'Required property 'properties' not found in JSON. Path '', line 1, position 93.'
@janusw
Copy link
Member

janusw commented Jul 3, 2023

Ran into the same problem today. Occurs e.g. when deserializing a very simple polygon geometry without any properties:

{
  "type":"Feature",
  "geometry": {
    "type":"Polygon",
    "coordinates": [..]
  }
}

@janusw
Copy link
Member

janusw commented Jul 6, 2023

Please allow Properties property to be nullable in JSON.

I think what you're asking is not to make the properties member nullable (it already is), but to allow it to be absent in JSON.

Tried to check the GeoJSON RFC on this matter, but it only says (see https://datatracker.ietf.org/doc/html/rfc7946#section-3.2):

      A Feature object has a member with the name "properties". The
      value of the properties member is an object (any JSON object or a
      JSON null value).

I'm not fully sure if this is actually meant to require the "properties" member to be always present. But from a "common sense" point of view, I see no reason why one shouldn't allow it to be absent (in case the feature does not have any relevant properties).

@tuyen-vuduc
Copy link
Author

@janusw In such case, we default it to JSON null value? Many JSON serializer omits NULL value from the serialized JSON.

@janusw
Copy link
Member

janusw commented Feb 28, 2024

This is fixed via #167 by now.

@janusw In such case, we default it to JSON null value?

No, as you can see from the test case I added, the properties will be non-null, but empty:

[Test]
public void Can_Deserialize_Feature_Without_Props()
{
var json = GetExpectedJson();
var feature = JsonConvert.DeserializeObject<Net.Feature.Feature>(json);
Assert.IsNotNull(feature);
Assert.IsNotNull(feature.Properties);
Assert.IsEmpty(feature.Properties);

@janusw
Copy link
Member

janusw commented Jul 7, 2024

@xfischer I think this issue can and should be closed (I don't have the necessary permissions do close it).

@xfischer xfischer closed this as completed Jul 8, 2024
@xfischer
Copy link
Member

xfischer commented Jul 8, 2024

@janusw I gave you the permissions as you've undoubtly gained the maintainer status ;)

@janusw
Copy link
Member

janusw commented Jul 8, 2024

@janusw I gave you the permissions as you've undoubtly gained the maintainer status ;)

Awesome, thanks! 👍

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

3 participants