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

Missing collection item when they are not wrapped during unmarshal with multiple namespaces #307

Closed
wanchongtai opened this issue Sep 1, 2018 · 2 comments
Milestone

Comments

@wanchongtai
Copy link

wanchongtai commented Sep 1, 2018

  1. I have the following xml to unmarshal
<?xml version="1.0" encoding="utf-8"?>
<customer xmlns="http://www.archer-tech.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <customerId>1</customerId>
    <customerName>Michael Judy</customerName>
    <account>
        <accountId>100</accountId>
        <accountName>Michael</accountName>
        <postcode xsi:nil="true"></postcode>
    </account>
    <account>
        <accountId>200</accountId>
        <accountName>Judy</accountName>
        <postcode xsi:nil="true"></postcode>
    </account>	
</customer>
  1. domains
@JacksonXmlRootElement(localName = "customer")
public class CustomerWithoutWrapper {
    Long customerId;
    String customerName;

    @JacksonXmlElementWrapper(useWrapping = false)
    List<Account> account = new ArrayList<>();
...setter/getter...
}

public class Account {
    Long accountId;
    String accountName;
    String postcode;
...setter/getter...
}
  1. unmarshal process
        ObjectMapper objectMapper = new XmlMapper();
        CustomerWithoutWrapper customerWithOutWrapper =
                objectMapper.readValue(getCustomerWithoutWrapperXml(), CustomerWithoutWrapper.class);
  1. result

there is not exception, however only the last account item is kept. the first account item is missing from account collection after unmarshalling

incorrect result

CustomerWithoutWrapper{customerId=1, customerName='Michael Judy', account=[Account{accountId=200, accountName='Judy', postcode=''}]}
  1. however when account items are wrapped as following, and change the domain mapping accordingly, then Jackson can unmarshall xml correctly.
    e.g.
<?xml version="1.0" encoding="utf-8"?>
<customer xmlns="http://www.archer-tech.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<customerId>1</customerId>
	<customerName>Michael Judy</customerName>
	<accounts>
		<account>
			<accountId>100</accountId>
			<accountName>Michael</accountName>
			<postcode xsi:nil="true"></postcode>
		</account>
		<account>
			<accountId>200</accountId>
			<accountName>Judy</accountName>
			<postcode xsi:nil="true"></postcode>
		</account>	
	</accounts>
</customer>
@JacksonXmlRootElement(localName = "customer")
public class CustomerWithWrapper {
    Long customerId;

    String customerName;

    @JacksonXmlElementWrapper(localName = "accounts")
    List<Account> account = new ArrayList<>();
...
}

result - correct when accounts are wrapped.

CustomerWithWrapper{customerId=1, customerName='Michael Judy', account=[Account{accountId=100, accountName='Michael', postcode=''}, Account{accountId=200, accountName='Judy', postcode=''}]}
@wanchongtai
Copy link
Author

re-attach xml file content

1 Michael Judy 100 Michael 200 Judy ====

@cowtowncoder cowtowncoder changed the title missing collection item when they are not wrapped during unmarshal with multiple namespaces Missing collection item when they are not wrapped during unmarshal with multiple namespaces Nov 13, 2020
@cowtowncoder cowtowncoder added this to the 2.12.0-rc2 milestone Nov 13, 2020
@cowtowncoder
Copy link
Member

This will be fixed in 2.12.0; added a test to verify; test failed for 2.11 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants