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.

localName = "" is not honored in @JacksonXmlElementWrapper

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
gulleryacommented, Oct 3, 2017

For anyone that comes here for the solution (like me): @XmlElement(name = 'something') is NOT working @JsonProperty('something') works OKAY

2reactions
schulz-mcommented, Dec 5, 2017

Actually, for me the solution was simply to revert the order of the XmlProperty and XmlElementWrapper - then everything seems to work as expected! For example:

@JacksonXmlProperty(localName = "Command")
@JacksonXmlElementWrapper(useWrapping = false)
public List<Command> lala;
Read more comments on GitHub >

github_iconTop 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 >

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