Skip to content

Trouble dealing with JacksonXMLText if properties are present or if element is in a collection #449

Open
@lonvarscsak

Description

@lonvarscsak

Given the xml of:

<project><text> </text></project>

and the Text.java of:

public class Text {
	private String content;

	public Text() {
	}

	@JacksonXmlText
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
}

The setContent method will be called with the whitespace contained in <text>. However, if I add (with Text.java having "id" as an attribute):

<project><text id="test"> </text></project>

The setContent call will be skipped when it only contains whitespace. However, non-whitespace only text:

<project><text id="test">hello world!</text></project>

would have setContent with "hello world!" passed in

Additionally, if I were to use the xml:

<project><text> </text><text>hello world!</text></project>

...and have Project contain a List of Texts (whether wrapped or unwrapped), it will result in the same failure. The second Text object will have the contents of "hello world!", but the first will contain null rather than it's whitespace.

I'm struggling with how to work around this as the items I'm dealing with really represent text in a document and sometimes I will have empty strings (which have meaning, but I could deal with those being null) or whitespace (spaces) which have meaning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions