question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserializing nested element list in XML - only first element returned.

See original GitHub issue

Expected Behavior

Create list of nested object

Actual Behavior

Created list of nested object with 1 actual object.

Steps to Reproduce the Problem

  1. Create an xml to deserialize that contains a custom xml element within the value of the root element. Make sure that the custom element is a list (has multiples) and has attributes.
  2. Deserialize XML.

Example XML: <orders order_id="1000052" publisher_id="8888" store_id="99999" billing_address_first_name="test" billing_address_last_name="tester" billing_address_street1="123 do not ship" billing_address_street2="" billing_address_city="Test City" billing_address_state_id="14" billing_address_postcode="80204" billing_address_country_id="1" billing_address_phone="5555550779" shipping_address_first_name="Test" shipping_address_last_name="Tester" shipping_address_street1="123 do not ship" shipping_address_street2="" shipping_address_city="test city" shipping_address_state_id="14" shipping_address_postcode="80204" shipping_address_country_id="1" shipping_address_phone="5555550779" shipping_address_business="0" shipping_address_validated="0" shipping_address_pobox="0" shipping_method_id="1000027" shipping_method="will distribute" print_cost="0.0000" retail_cost="0.0000" retail_amount="190.0000" shipping_amount="0.0000" process_markup_amount="0.0000" tax_amount="0.0000" total_amount="190.0000" giftcert_amount="0.0000" amount_due="190.0000" ip_address="" date_created="2018-03-09T08:32:54.473" last_modified="2018-03-26T10:39:41.033" email="" process_amount="190.0000" payment_method="CREDITCARD" authorized="1" confirmed="1" rendered="0" ordered="0" received="0" prepared="0" paid="1" shipped="0" cancelled="0" estimated_ship_date="2018-04-16T20:00:00" estimated_delivery_min_date="2018-04-16T20:00:00" estimated_delivery_max_date="2018-04-16T20:00:00" currency_code="USD" hide_pricing="0" currency_symbol="$" tax_name="Tax" print_method_list="None" printed="0" in_production_manager="0" production_status="Confirmed"> <order_retail_items order_retail_item_id="1000075" price="16.5000" price_overridden="0" base_product_price="16.5000" print_method="None" printed="0"> <retail_product retail_product_id="1000046" product_id="1000086" sku="test1" product_style_id="1001050" style="Vintage Red"> <order_retail_item_sizes order_retail_item_size_id="1000077" quantity="1" product_style_size_id="1007196" size="2XL" render_attempt="0" price="16.5000" product_cost="0.0000" product_price="16.5000" print_cost="0.0000" quantity_discount_amount="0.0000" print_name_numbers="0.0000" price_each="16.5000" product_price_each="16.5000" print_cost_each="0.0000" print_setup_each="0.0000"> <order_retail_item_size_namenumbers> <order_retail_item_size_add_ons /> </order_retail_item_size_namenumbers> </order_retail_item_sizes> </retail_product> </order_retail_items> <order_retail_items order_retail_item_id="1000076" price="15.0000" price_overridden="0" base_product_price="15.0000" print_method="None" printed="0"> <retail_product retail_product_id="1000047" product_id="1000087" sku="test2" product_style_id="1001052" style="Vintage Navy"> <order_retail_item_sizes order_retail_item_size_id="1000078" quantity="1" product_style_size_id="1007200" size="LG" render_attempt="0" price="15.0000" product_cost="0.0000" product_price="15.0000" print_cost="0.0000" quantity_discount_amount="0.0000" print_name_numbers="0.0000" price_each="15.0000" product_price_each="15.0000" print_cost_each="0.0000" print_setup_each="0.0000"> <order_retail_item_size_namenumbers> <order_retail_item_size_add_ons /> </order_retail_item_size_namenumbers> </order_retail_item_sizes> </retail_product> </order_retail_items> </orders> </OrderDetail>

Possible Solution:

I fixed this issue by switching two If/Else statements in XMLDeserializer.cs

I moved the block of code associated with line 264: “else if (type.IsGenericType)” below the next else if statement “else if (asType.IsSubclassOfRawGeneric(typeof(List<>)))”. This second block of code seems to handle this situation and the others that the type.IsGenericType does.

I can check in this change to a branch if this change is desired.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kd5ziycommented, Jul 31, 2019

@alexeyzimarev this became an issue again for me while using the XML deserializer. I’ve made some changes to the code that succeeds through the unit tests in place and have added one to test the change.

If possible, I would like to have these changes included in an upcoming release of Restsharp so that I can stay with the main branch of versions.

I will put in a pull request. Let me know if you would like any changes.

0reactions
repo-ranger[bot]commented, Apr 6, 2020

⚠️ This issue has been marked wontfix and will be closed in 3 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deserializing nested element list in XML
Deserializing nested element list in XML - only first element returned. ... I just read the Contributing.md on the github for RestSharp.
Read more >
c# - Deserialize nested xml only
I want to deserialize only the users node. Here is what I'm doing. XmlSerializer serializer = new XmlSerializer(typeof(List<User>), ...
Read more >
Controlling XML Serialization Using Attributes
Attributes can be used to control the XML serialization of an object or to create an alternate XML stream from the same set...
Read more >
Simple 2.7.1
Serializing a simple object; Deserializing a simple object; Nested object serialization; Optional elements and attributes; Reading a list of elements ...
Read more >
Processing XML
The value could be any Object , the value will be serialized to its String representation. Creating XML nested elements. def xmlWriter =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found