[SOLVED] Not required nested string field throws JsonSerializationException if value is null

I’m submitting a…

  • [ x] Bug report

Current behavior

We added a “string” nested field to a scheme. In the validation settings of the field, the “Required” property is disabled.

After adding the content and not filling the corresponding field, the api call produces the following error:

An unhandled exception occurred while processing the request.

JsonSerializationException: Required property ‘service-7’ expects a non-null value. Path ‘data.service-block.iv[2]’, line 1, position 1930.

Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EndProcessProperty(object newObject, JsonReader reader, JsonObjectContract contract, int initialDepth, JsonProperty property, PropertyPresence presence, bool setDefaultValue)

This is because we used the CSharpCielntGenerator which generated the properties based on swagger (NSwag) as follows: “Required = Newtonsoft.Json.Required.DisallowNull”
image

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Version: [4.0.3]

1 Like

What do you mean with nested field?

Btw: I have disabled this behavior: https://github.com/Squidex/squidex-samples/blob/master/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs#L23

I will make a fix for the nullable thing. But in general I recommend to turn the setting off in the code generator. The reason is that when you add a field or the required-validation later you have no guarantee that the field is not null and then you don’t want to crash.