We are using Umbraco v7.5.7, Archetype v1.13.0, Newtonsoft v6.0.0 and RJPMultiUrlPicker v1.3.1 and are experiencing the following issue.
We have a class as follows:
public class LinkItem : ArchetypeFieldsetModel
{
public int? Id { get; set; }
public string Name { get; set; }
public string Target { get; set; }
public LinkType Type { get; set; }
public string Url { get; set; }
}
and have created a custom TypeConverter that has the following method:
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
var result = JsonConvert.DeserializeObject<List<LinkItem>>(value.ToString());
return result;
}
when this runs we are getting the following error message:
[ArgumentException: Could not cast or convert from System.String to System.Guid.]
Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType) +225
Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType) +123
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) +348
[JsonSerializationException: Error converting value "1098" to type 'System.Guid'. Path '[0].id', line 3, position 17.]
which is confusing as the object it is trying to be converted to does not have a Guid declared. The source JSON data looks as follows:
This was working in an earlier version of Umbraco (v7.1.9) and Archetype (v1.7.5) with the same version of RJPMultiUrlPicker and Newtonsoft but now no longer works as above.
Thanks for the reply. I can confirm that I tried both ways such as changing the class to:
public class LinkItem : ArchetypeFieldsetModel
{
public string Id { get; set; }
public string Name { get; set; }
public string Target { get; set; }
public LinkType Type { get; set; }
public string Url { get; set; }
}
as well as removing the quotes around the id. As mentioned this all worked fine in an earlier version of Umbraco/Archetype (Newtonsoft and RJPMultiUrlPicker being the same versions as previous) so can't understand what the difference is. I have also checked the returned JSON in the previous version and it is identical!!
RJPMultiUrlPicker deserializing issue
We are using Umbraco v7.5.7, Archetype v1.13.0, Newtonsoft v6.0.0 and RJPMultiUrlPicker v1.3.1 and are experiencing the following issue.
We have a class as follows:
and have created a custom TypeConverter that has the following method:
when this runs we are getting the following error message:
which is confusing as the object it is trying to be converted to does not have a Guid declared. The source JSON data looks as follows:
This was working in an earlier version of Umbraco (v7.1.9) and Archetype (v1.7.5) with the same version of RJPMultiUrlPicker and Newtonsoft but now no longer works as above.
Any ideas???
Hi Graham,
Have you tried changing the id:"1111" to id:1111?
As the value of id is expected to be of type integer, yet the json id is of type string.
Hi Rasmus,
Thanks for the reply. I can confirm that I tried both ways such as changing the class to:
as well as removing the quotes around the id. As mentioned this all worked fine in an earlier version of Umbraco/Archetype (Newtonsoft and RJPMultiUrlPicker being the same versions as previous) so can't understand what the difference is. I have also checked the returned JSON in the previous version and it is identical!!
Hi Graham,
I belive I found the fault.
You are inheriting ArchetypeFieldsetModel which has a property of type guid, goes by name id, and has attribute [JsonProperty]
https://github.com/kgiszewski/Archetype/blob/master/app/Umbraco/Umbraco.Archetype/Models/ArchetypeFieldsetModel.cs#L24
So when you try to deserialize the object, it uses the one which is assigned with JsonProperty over your LinkItem id property.
Try adding attribute [JsonProperty("id")] to your LinkItem Id property.
Though I dont think that it will work, but try anyways.
is working on a reply...