Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DennisGoermannMD opened this issue Dec 2, 2021 · 1 comment

Comments

@DennisGoermannMD
Copy link

DennisGoermannMD commented Dec 2, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant