Skip to content

Commons-lang3 toString style does not fit the expected style of to-string-verifier #59

@DennisGoermannMD

Description

@DennisGoermannMD

Hello,

we use apache common-lang3 to generate toString presentations. Starting with commons-lang3 3.11 the output was changed for maps. See https://issues.apache.org/jira/browse/LANG-1543
If we update the apache dependency our test will failed due the to-string-verifier does not expect this new style.

Please fix this.

Example:

public class Example {

	private Map<String, Integer> exampleMap;

	public Map<String, Integer> getExampleMap() {
		return exampleMap;
	}

	public void setExampleMap(Map<String, Integer> exampleMap) {
		this.exampleMap = exampleMap;
	}

	@Override
	public String toString() {
		return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).append("class", this.getClass().getCanonicalName())
				.toString();
	}
}
@Test
	public void testExampleToString() {
		ToStringVerifier.forClass(Example.class).verify();
	}

the result with to-string-verifier 1.4.8 is:
java.lang.AssertionError:

Failed verification:

com.Example

Expected auto generated toString:
{"class":"com.Example","exampleMap":{"3585d9b7-9589-4a2c-a291-151b6d5551df":-1387581510}}

To contain fields with values:
  - exampleMap: {3585d9b7-9589-4a2c-a291-151b6d5551df=-1387581510

The problem seems to be the equals-sign "=". It was replaced with ":" for legal json representation.

With kind regards
Dennis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions