-
Notifications
You must be signed in to change notification settings - Fork 620
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
Add Json configuration flag to allow comments #2592
Conversation
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/AbstractJsonLexer.kt
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/CommentLexers.kt
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/StringJsonLexer.kt
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/ReaderJsonLexer.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Filipp Zhinkin <filipp.zhinkin@gmail.com>
import kotlinx.serialization.json.* | ||
import kotlin.test.* | ||
|
||
class JsonCommentsTest: JsonTestBase() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need special tests for StringJsonLexer
and ReaderJsonLexer
. We now have two decoding branches that can be modified independently of each other.
Since JSON without comments is actually a subset of JSON with comments, it is necessary to test it for both cases.
We can do this by running all the JSON tests for allowComments = true
, however, this will be very redundant.
It is easier to identify the main decoding cases and write a limited set of tests for them, which works the same regardless of the source (String or Reader) and the settings (with or without comments)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid we do not have particular 'main decoding cases' tests. The closes place I can think of is Json spec tests:
Line 27 in 5e8ccad
class SpecConformanceTest { |
Do you think it is enough to add allowComments = true
there?
Also, 'JsonCommentsTest' may be already enough because it has arrays, nested objects, and strings, and there's really not much anything else in the json spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think SpecConformanceTest will be enough.
After all, this flag only changes parsing, but not the serialization logic.
formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonCommentsTest.kt
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/CommentLexers.kt
Show resolved
Hide resolved
formats/json-tests/commonTest/src/kotlinx/serialization/features/JsonCommentsTest.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/lexer/CommentLexers.kt
Show resolved
Hide resolved
Could you also please show the benchmark results? |
I believe |
For other benchmarks Before (
After:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
@shanshin PTAL at changes at SpecConformanceTest |
in C/Java style for both string and stream parser.
This flag, together with allowTrailingCommas and isLenient, will help to cover most use cases for Json5, such as configuration files.
Fixes #2221
Fixes #797