to-string-verifier icon indicating copy to clipboard operation
to-string-verifier copied to clipboard

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

Open DennisGoermannMD opened this issue 3 years ago • 1 comments

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

DennisGoermannMD avatar Dec 02 '21 12:12 DennisGoermannMD

Commons-lang3 >3.11 has more changes to the string style. Now the output will be legal json!

DennisGoermannMD avatar Dec 02 '21 13:12 DennisGoermannMD