localName = "" is not honored in @JacksonXmlElementWrapper
See original GitHub issueI have a class that looks like
public class UserActivityList {
@JacksonXmlProperty(localName = "username")
private String userName;
@JacksonXmlElementWrapper(useWrapping=false, localName = "user_activity")
private List<UserActivity> userActivity;
public void setUserActivity(List<UserActivity> userActivity) {
this.userActivity = userActivity;
}
@Override
public String toString() {
return "UserActivityList{" +
"userName='" + userName + '\'' +
", userActivity=" + userActivity +
'}';
}
}
When I run this code, I get the following error
[main] ERROR c.e.tenant.internal.StealthWatch - Error in parsing response from Stealthwatch: {}
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "user_activity" (class com.project.tenant.internal.response.UserActivityList), not marked as ignorable (2 known properties: "userActivity", "username"])
at [Source: java.io.StringReader@3059cbc; line: 10, column: 33] (through reference chain: com.project.tenant.internal.response.StealthWatchResponse["service"]->com.project.tenant.internal.response.Service["action"]->com.project.tenant.internal.response.Action["user_activity_list"]->com.project.tenant.internal.response.UserActivityList["user_activity"])
The way I currently solve it is
@JacksonXmlElementWrapper(useWrapping = false)
private List<UserActivity> user_activity;
public void setUser_activity(final List<UserActivity> user_activity) {
this.user_activity = user_activity;
}
The detail question is here Is it a bug or I missed something?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Jackson xml 2.9.0: @JacksonXmlElementWrapper not ...
My failed attempts include: Replacing @JacksonXmlElementWrapper(localName = "brokenChildList") with @JacksonXmlElementWrapper will rename ...
Read more >JacksonXmlElementWrapper (Jackson-dataformat-XML 2.9.9 ...
Annotation Type JacksonXmlElementWrapper ... If defined, a separate container (wrapper) element is used; if not, ... public abstract String localName.
Read more >Solving the XML Problem with Jackson - Stackify
Looking for a mature, flexible way of working with both JSON and XML for ... class Wrapper { @JacksonXmlElementWrapper(localName = "list") ...
Read more >Solving the XML Problem with Jackson - DZone
Note that some of these settings might not work with some XML ... class Wrapper { @JacksonXmlElementWrapper(localName = "list") private List ...
Read more >Jackson 2.12: improved XML module - cowtowncoder - Medium
Case-insensitivity of properties not working ([dataformat-xml#273]) ... should not: either due to namespace being ignored (i.e. local name ...
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
For anyone that comes here for the solution (like me):
@XmlElement(name = 'something')
is NOT working@JsonProperty('something')
works OKAYActually, for me the solution was simply to revert the order of the XmlProperty and XmlElementWrapper - then everything seems to work as expected! For example: