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

try to fix duplicated fields in attribute and child element #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stzdzyhs
Copy link

@stzdzyhs stzdzyhs commented Sep 25, 2017

Hi, this pull request to try to fix duplicated name in attribute and child element like following xml:

<mapper namespace="com.test.dao.mapper1" >
<resultMap id="mapArticle" type="com.test.dao.Mapper1" >
	<id     column="no"       property="articleNo"/>
	<result column="title"       property="title"/>
</resultMap> 
</mapper>

resultMap has both attribute and child element named with "id".
this is mybatis(http://www.mybatis.org) mapper xml.

I know that the fix will fail some other testcases, because this is only fix using in annotation.
just not sure if the fix is right way to go.
Thanks!

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 79.753% when pulling 0b8a029 on stzdzyhs:master into 7896b8e on x-stream:master.

@joehni
Copy link
Member

joehni commented Sep 25, 2017

XStream actually works internally only on a parent-child-hierarchy. It is syntactic sugar, that you can setup XStream to read/write the value of a child as attribute instead. In fact, even if you have configured a child element to be an attribute, it is still read from a child element if the attribute is not present. XStream does not separate between child elements and attributes and does therefore not support mapping to different fields for the same identifier used for the attribute and element name.

You can implement a workaround using a custom mapper (see XStream' acceptance test CustomMapperTest for some ideas) to circumvent the limitation for a specific case, but that will not be a general solution.

@joehni joehni self-assigned this Sep 25, 2017
@stzdzyhs
Copy link
Author

stzdzyhs commented Sep 26, 2017

Thanks for your suggestion !
another is, I actually forget to commit some code in the previous pull request,
because the code is still in testing, not in good-shape, I do not make another pull request,
please see on
https://github.com/stzdzyhs/xstream.git

in my testing (TestMapper.java), after apply the fix, it can get the resultMap.id in the mapper1.xml.
in previous release, the resultMap.id is "overwritten" by the resultMap.id1

Regards

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

Successfully merging this pull request may close these issues.

4 participants