hi all - does hoplite support polymorphic types.. ...
# hoplite
p
hi all - does hoplite support polymorphic types.. sum type really? (in HOCON if it matters)
eg
Copy code
sealed interface Lamp {
    object StandardLamp: Lamp
    data class SpecialLamp(val brightness: Int): Lamp
}

data class Config(
    val lamp: Lamp = Lamp.StandardLamp
)
i can do that with kotlinx.serialization.hocon (though must be a sealed class rather) .. it needs a type hint in the HOCON
oops, missed it the first time round: https://github.com/sksamuel/hoplite#sealed-classes
s
Yep, sealed classes and interfaces
🙌 1
You might run into some edge cases if the fields align
p
based on field types?
s
Copy code
sealed interface Foo {
    data class Bar1(val a: String): Foo
    data class Bar2(val a: String): Foo
}
p
👍
good to know
s
Like that, super edge case-y but the system wouldn't know which to pick in that case
p
are you opposed to a type hint in the serialized format?
s
Not opposed, if there's a use case for it
👍 1
p
doesn’t look like it supports
object
s unfortunately 😞
ie 0 fields
s
how would it do that, the absense of any values ?
p
maybe?
Copy code
{
  lamp = { }
}
i haven’t looked at how it works internally
s
That might work for json stuff yeah
sounds like it would be fairly easy to do
p
😅
s
1.4.16 is syncing to Maven now.
p
awesome, thank you!! 🙌
s
Let me know if you have an issues
p
works great - thanks again! 🙏
👍🏻 1
j
Oh this is nice, I had to use a wrapper config class with the object as the default value