File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
main/scala/com/avsystem/commons/hocon
test/scala/com/avsystem/commons/hocon Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ package com.avsystem.commons
22package hocon
33
44import com .avsystem .commons .annotation .explicitGenerics
5- import com .avsystem .commons .serialization ._
5+ import com .avsystem .commons .serialization .*
6+ import com .avsystem .commons .serialization .cbor .RawCbor
7+ import com .avsystem .commons .serialization .json .RawJson
68import com .typesafe .config .{ConfigValue , ConfigValueFactory }
79
810object HoconOutput {
@@ -31,7 +33,14 @@ class HoconOutput(consumer: ConfigValue => Unit) extends OutputAndSimpleOutput {
3133 def writeList (): HoconListOutput = new HoconListOutput (consumer)
3234 def writeObject (): HoconObjectOutput = new HoconObjectOutput (consumer)
3335
34- // TODO: writeCustom
36+ // TODO: handle other markers in writeCustom? Unfortunately typesafe config does not provide a methods to write
37+ // duration to nice string representation etc.
38+ override def writeCustom [T ](typeMarker : TypeMarker [T ], value : T ): Boolean =
39+ typeMarker match {
40+ case ConfigValueMarker => consumer(value); true
41+ case PeriodMarker => anyRef(value.toString.toLowerCase.stripPrefix(" p" )); true
42+ case _ => false
43+ }
3544}
3645
3746class HoconListOutput (consumer : ConfigValue => Unit ) extends ListOutput {
Original file line number Diff line number Diff line change 11package com .avsystem .commons
22package hocon
33
4+ import com .avsystem .commons .hocon .HoconInputTest .CustomCodecsClass
45import com .avsystem .commons .serialization .{GenCodecRoundtripTest , Input , Output }
5- import com .typesafe .config .ConfigValue
6+ import com .typesafe .config .{ConfigFactory , ConfigValue }
7+
8+ import java .time .{Duration , Period }
9+ import scala .concurrent .duration .*
610
711class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {
812 type Raw = ConfigValue
@@ -15,4 +19,17 @@ class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {
1519
1620 def createInput (raw : ConfigValue ): Input =
1721 new HoconInput (raw)
22+
23+ test(" custom codes class" ) {
24+ val value = CustomCodecsClass (
25+ duration = 1 .minute,
26+ jDuration = Duration .ofMinutes(5 ),
27+ fileSize = SizeInBytes .`1KiB`,
28+ embeddedConfig = ConfigFactory .parseMap(JMap (" something" -> " abc" )),
29+ period = Period .ofWeeks(2 ),
30+ clazz = classOf [HoconGenCodecRoundtripTest ],
31+ clazzMap = Map (classOf [HoconGenCodecRoundtripTest ] -> " abc" ),
32+ )
33+ testRoundtrip(value)
34+ }
1835}
You can’t perform that action at this time.
0 commit comments