JSON Property Name Not Being Taken From XMLElementWrapper

96 views
Skip to first unread message

David Driver

unread,
Jan 24, 2017, 4:07:26 PM1/24/17
to jackson-user
I'm creating json from JAXB annotated classes. While this works fine for most classes in the code base, I've been having some trouble with XmlElementWrapper. I've enabled the feature USE_WRAPPER_NAME_AS_PROPERTY_NAME, yet I keep getting an error about multiple fields having the same name.

The following is a minimal class to reproduce the problem:
@XmlAccessorType(XmlAccessType.FIELD)
public class MyClass {
   
@XmlElement(name="value")
   
private String currentValue;

   
@XmlElementWrapper(name="previousValues")
   
@XmlElement(name="value")
   
private String[] previousValues;

}

The issue was encountered using version 2.5.4 (and reproduced with 2.8.6). After some investigation I found the cause to be in POJOPropertiesCollector._renameWithWrappers(). The method looks like it expects to do a one-one renaming, so having two fields with the same XmlElement name causes it fall over before it actually reads the name on the XmlElementWrapper. To me this is odd because you know you may change some names, so duplicates shouldn't matter until renaming is complete. The XmlElement annotation on the array should not affect anything because I've enabled the USE_WRAPPER_NAME_AS_PROPERTY_NAME feature.

I understand that xml and json have different approaches to this, so my main question is if this is a bug or intentional?

Thanks in advance.

Reply all
Reply to author
Forward
0 new messages