[default-extension,serde-hjson] Fix validation interfering with normal comments; improve HJSON comment writing

This commit is contained in:
2025-10-06 22:47:19 +02:00
parent 7c9d4a95bb
commit d06ac7cb7e
4 changed files with 38 additions and 8 deletions

View File

@@ -293,18 +293,21 @@ public class HjsonWriter implements TweedDataWriter {
private void writeCommentLine(HjsonCommentType commentType, CharSequence text, int begin, int end) {
writeCurrentIndentIfApplicable();
write(getCommentLineStart(commentType));
write(text, begin, end);
if (end > begin) {
write(" ");
write(text, begin, end);
}
writeLineFeed();
}
private CharSequence getCommentLineStart(HjsonCommentType commentType) {
switch (commentType) {
case HASH:
return "# ";
return "#";
case SLASHES:
return "// ";
return "//";
case BLOCK:
return " * ";
return " *";
default:
throw new IllegalStateException("Unknown comment type: " + commentType);
}