[ARCHIVED] Error creating a record with de Client Manager

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [X] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Environment

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

Version: 3.1.0
Squidex.ClientLibrary: 3.7.0

Others:
Client Manager .Net Core

I have a scheme and corresponding models:

public sealed class Customer : SquidexEntityBase<CustomerData>
{
}

public class CustomerData
{
	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("fullName")]
	public string FullName { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("customerNumber")]
	public int CustomerNumber { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("address")]
	public string Address { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("country")]
	public string Country { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("email")]
	public string Email { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("phone")]
	public string Phone { get; set; }

	[JsonConverter(typeof(InvariantWriteConverter))]
	[JsonProperty("sendNewsletter")]
	public bool SendNewsletter { get; set; }
}

Service Code:

public async Task<Result<Customer>> PostCustomerAsync(CustomerData model)
{
	try
	{
		var client = _clientManager.GetClient<Customer, CustomerData>("customer");
		var result = await client.CreateAsync(model);

		return await result.ToResultAsync();
	}
	catch (Exception ex)
	{
		_logger.LogError(ex.Message, ex);
		return new Result<Customer>(new Customer(), StatusTypes.Error, ex.Message);
	}
}

The JSON file which is transmitted in my case is:

{
  "fullName": "Andreas",
  "customerNumber": 100001,
  "address": "Musterstrasse 99\n9000 St. Gallen",
  "country": "Schweiz",
  "email": "andreas@webnerds.ch",
  "phone": "+41 (0)00 000 00 00",
  "sendNewsletter": true
}

If I run the code now, a record will be created, but there will be an error:

“Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type ‘System.String’ because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly. To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path ‘data.fullName.iv’, line 1, position 153.”

The InvariantWriteConverter is perhaps named very badly, because it means that it only makes the invariant conversion when writing.

If you use the InvariantConverter it should work.

I tried that and got the following error:

example:

public class ContactData
    {
        [JsonConverter(typeof(InvariantConverter))]
        public string Name { get; set; }

        [JsonConverter(typeof(InvariantConverter))]
        public string Email { get; set; }

        [JsonConverter(typeof(InvariantConverter))]
        public string Message { get; set; }

        [JsonConverter(typeof(InvariantConverter))]
        public bool Read { get; set; }
    }

{
  "errors": {
    "read": [
      "Property must have a invariant language property."
    ],
    "email": [
      "Property must have a invariant language property."
    ]
  },
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "0HLP0NM8JDK72:00000003"
}

Can you post the json request of your second example? For me everything looks good and the client manager has a few integration tests which work fine.