-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
JSON5: Provide a way to read/write a comment using JsonNode
#734
Comments
Ok. So, it might be possible to write some comments through One thing that might be doable on reading side would be to allow registration of a callback to call when comment is encountered. This alone would only work at lowest level and require caller to handle difference between tokens read, comments, and somehow retain comment information. Further, any stylistic knowledge (white-space surrounding comment) would be lost. So... while I can understand the need for exposing comments, I have never figured out a way they could be nicely handled at API level. In XML things are bit easier than JSON, in this case. |
First of all, thank you for your interest in this issue. 🙇♂️
Agreed. It should be difficult to fully support comments. I speculated that some limited comments could be retained in positions right above nodes as a known limitation. {
// A single line note for a node
foo: "bar",
/**
* Multiline note for a node
* could be supported.
*/
hello: "world"
}
I'm not so sure that the following API style is possible but I just imagined: interface CommentableNode {
String comment();
}
public class CommentableArrayNode extends ArrayNode implements CommentableNode {
...
}
JsonNode node = ...;
if (node instanceof CommentableNode) {
// do something with the comment
} |
Unfortunately I don't thing add-on interfaces help a lot with the core issue (or maybe I just don't see it). |
I'd like to parse JSON5 containing comments.
JsonReadFeature#ALLOW_JAVA_COMMENTS
ignores comments when deserializing a JSON into aJsonNode
.jackson-core/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java
Lines 2521 to 2523 in 0fbb529
As a result, we lose the comment information and cannot read/recover the original content from the parsed
JsonNode
.A commentable
JsonNode
is useful so as to retrieve the original comment and serialize the JsonNode to JSON5 format.The text was updated successfully, but these errors were encountered: