YamlDotNet
YamlDotNet copied to clipboard
Enable deserealization of types without default constructor
Using TypeConverter for this is quite complicated and as far as I understand full parsing needs to be implemented. The feature is present in Json.Net and I expected to find it here too. Some interfaces for ctor parameter's name and value conversion would be great too.
At first I didn't think this would be possible. You can't usually deserialize something that doesn't have a default constructor. In order to deserialize it needs to know what constructor it can call, and also what parameters of that constructor map to the properties it's trying to set. The deserializer has neither of those critical pieces of info and thus it can't work. After I looked around some I realized that the Jackson serializer for Java accomplishes this using Annotations.
@JsonCreator
public ImportResultItemImpl(@JsonProperty("name") String name,
@JsonProperty("resultType") ImportResultItemType resultType,
@JsonProperty("message") String message) {
super();
this.resultType = resultType;
this.message = message;
this.name = name;
}
I'm sure a similar approach is possible in JsonDotNet. If I can find the time maybe I'll code it up.
This issue appears to be abandoned, I'm going to close it.