Error while deserializing function with nullable return to xml
See original GitHub issueHi,
Autorest generated classes won’t compile when generating this json function:
"/api/DataManager/DoesTechnologyNameExistsInBrand": {
"post": {
"tags": [
"DataManager"
],
"operationId": "DataManager_DoesTechnologyNameExistsInBrand",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "technologyName",
"in": "query",
"required": true,
"type": "string",
"x-nullable": true
},
{
"name": "brandId",
"in": "query",
"required": true,
"type": "integer",
"format": "int32",
"x-nullable": false
},
{
"name": "technology",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/tblTechnology"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean",
"x-nullable": false
}
}
}
}
},
This fragment:
bool? _tmp_ = null;
if (_httpResponse.Content.Headers.ContentType.MediaType == "application/xml" &&
XmlSerialization.Root(XmlSerialization.ToDeserializer(e => (bool)e))(System.Xml.Linq.XElement.Parse(_responseContent), out _tmp_))
{
_result.Body = _tmp_;
}
else
{
_result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject<bool?>(_responseContent, Client.DeserializationSettings);
}
Generates an error:
Argument 2: cannot convert from ‘out bool?’ to ‘out bool’
Because out _tmp is bool but the variable is declared as bool?.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Can XmlSerializer.Deserialize ever return null? - Stack Overflow
Yes, Deserialize can return null when the input does not contain the XML that is expected. This is frequently seen when there is...
Read more >XmlSerializer.Deserialize Method (System.Xml.Serialization)
Deserializes an XML document contained by the specified XmlReader and allows the overriding of events that occur during deserialization.
Read more >XML Serializer object's property retuns null - Unity Forum
I am trying to create a data class from a xml file . it's work great on <Object> element and it give me...
Read more >Getting null in nested elements when deserializing xml-C
Your deserialization fails because, in the sample XML, these elements are not in any namespace. Why is this happening? It's because all your...
Read more >The Serializer Component (Symfony Docs)
Converting Property Names when Serializing and Deserializing ... DateTime $createdAt; // Getters public function getAge(): int { return $this->age; } ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m experiencing the same problem - although it’s not just generating the same non-compiling method above - it’s also generating a missing method:
Where .XmlDeserialize(e) in LocalizedContent.XmlDeserialize(e) doesn’t exist.
If XML support is only for a specific scenario, is it not possible to turn it off by default and enable by configuration switch?
The added complexity I have is that one of my operations has to return an XML document (it’s a signed XML document) - which seems to trigger this behaviour.
This is off by default now. Please reopen or post a new issue if you encounter related issues.