-
Notifications
You must be signed in to change notification settings - Fork 623
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
Support encode/decode java.time.Duration and ConfigMemorySize in HOCON #2094
Conversation
Hi, Leonid @sandwwraith! 👋 |
2706a1a
to
72d0310
Compare
72d0310
to
576b942
Compare
Hi! I've scanned through this and your other PRs. It seems the key problem here is, as you said, when (decoder) {
is Hocon.ConfigReader -> decoder.getValueFromTaggedConfig(decoder.getCurrentTag(), valueResolver)
is Hocon.ListConfigReader -> decoder.getValueFromTaggedConfig(decoder.getCurrentTag(), valueResolver)
is Hocon.MapConfigReader -> decoder.getValueFromTaggedConfig(decoder.getCurrentTag(), valueResolver)
else -> throw UnsupportedFormatException("ConfigMemorySizeSerializer")
} Which uses internal classes and internal function if (decoder is HoconDecoder)
(config, path) = decoder.currentValue()
else
error("Can be decoded only by Hocon") I'm unsure if both |
576b942
to
598c83e
Compare
Hi, Leonid @sandwwraith ! |
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 haven't reviewed the tests yet)
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/JBeanSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/JDurationSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconDecoder.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconDecoder.kt
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Serializer for [ConfigMemorySize]. | ||
* For decode using [HOCON Size in bytes format](https://github.com/lightbend/config/blob/main/HOCON.md#size-in-bytes-format). |
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 sorry, I can't quite understand what you mean here. Are you saying decoding accepts all possible values from the spec (including powers of two and ten)? And encoding always emits powers of two?
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.
Yes, when decoding, can use all formats from the specification. For encoding, I selected on one option - to use powers of two, as it is easier to implement.
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.
Then please rewrite the documentation as in JavaDurationSerializer
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.
Bump: Rewrite as 'All possible Hocon size formats....'
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.
Fixed
.../hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/ConfigMemorySizeSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/JDurationSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/JDurationSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/JDurationSerializer.kt
Outdated
Show resolved
Hide resolved
598c83e
to
18bd76b
Compare
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconDecoder.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconEncoder.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconEncoder.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/HoconEncoder.kt
Show resolved
Hide resolved
formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/internal/HoconDuration.kt
Outdated
Show resolved
Hide resolved
.../hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/ConfigMemorySizeSerializer.kt
Outdated
Show resolved
Hide resolved
.../hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/ConfigMemorySizeSerializer.kt
Outdated
Show resolved
Hide resolved
formats/hocon/src/test/java/kotlinx/serialization/hocon/TestJavaBean.java
Outdated
Show resolved
Hide resolved
formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconJavaDurationTest.kt
Show resolved
Hide resolved
formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconMemorySizeTest.kt
Outdated
Show resolved
Hide resolved
18bd76b
to
eecbdd3
Compare
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, only file name and minor comments left (please re-check Github's hidden converstaions section)
|
||
/** | ||
* Serializer for [ConfigMemorySize]. | ||
* For decode using [HOCON Size in bytes format](https://github.com/lightbend/config/blob/main/HOCON.md#size-in-bytes-format). |
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.
Bump: Rewrite as 'All possible Hocon size formats....'
|
||
@Test | ||
fun testSerializeDuration() { | ||
Hocon.encodeToConfig(Simple(ofMinutes(10))).assertContains("d = 10 m") |
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.
Same here: why don't write function similar to testMemorySize
?
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.
Implemented the testJavaDuration function
@alexmihailov Hi, do you have time to finish this on this week? I plan to release 1.5.0 soon. |
Hello! Thursday/Friday I will try to finish |
eecbdd3
to
aee6cf2
Compare
@sandwwraith Hi! I checked the hidden sections of conversations and made corrections. I'm sorry I didn't notice right away. |
.../hocon/src/main/kotlin/kotlinx/serialization/hocon/serializers/ConfigMemorySizeSerializer.kt
Outdated
Show resolved
Hide resolved
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.
Thank you very much for all your time!
Many use cases require serialization support for
java.time.Duration
. It is not possible to implement a custom serializer in user code, since private methods fromkotlinx.serialization.hocon.Hocon
andkotlinx.serialization.hocon.AbstractHoconEncoder
are required. To do this, I implemented theJDurationSerializer
serializer, which can be used in user code.Hocon supports the memory size format. Documentation.
In the
com.typesafe.config
library, theConfigMemorySize
class is responsible for this functionality. There is no way in user code to implement a serializer for this class. So I've implemented aConfigMemorySizeSerializer
that allows to serializeConfigMemorySize
.The
com.typesafe.config
library can create configuration using Java Bean notation. Thecom.typesafe.config.ConfigBeanFactory.create
method is used for this. To support this functionality, I've implemented aJBeanSerializer
that can only be used to decode configuration into a Java Bean class.This PR depends on the previous PR