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

Enable deserealization of types without default constructor #156

Closed
stanislav-a-frolov opened this issue Dec 7, 2015 · 2 comments
Closed

Comments

@stanislav-a-frolov
Copy link

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.

@NightWatchman
Copy link

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.

@EdwardCooke
Copy link
Collaborator

This issue appears to be abandoned, I'm going to close it.

@EdwardCooke EdwardCooke closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants