Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.0
-
Fix Version/s: 2.0-beta-3
-
Component/s: None
-
Labels:
-
Number of attachments :
Description
Using @ToString(includeNames = true) inserts a field called $print$names into the class. This field is neither transient nor static, which causes havoc when using XStream.
Example XStream output:
[
{
"name": "み +()[]{}.mp3",
"size": 690037,
"outputSize": 0,
"format": {
"codec": "mp3",
"name": "mp3",
"bitDepth": "s16le",
"samplingRate": 44100,
"channels": 2,
"$print$names": true
}
}
]
I don't understand why the field is there in the first place since printNames is a compile-time thing.
The reason for its existence is for legacy behavior of @Immutable which calls through to @ToString. With @Immutable classes created using the named params constructor automatically print out with printNames true whereas ones created with a tuple constructor don't. Current thinking is that we may deprecate this behavior as we have had no feedback indicating that it is absolutely essential for some particular use case and it does add complexity.
The field is marked "synthetic" and that is enough for some tools to ignore it - for XStream you would have to add an XStream annotation to ignore it or write your own convertor. CGLibConverter for example ignores synthetic fields I believe. This would be the workaround.
You mention "causes havoc". What exactly do you observe?