File tree 2 files changed +29
-3
lines changed
main/scala/com/avsystem/commons/hocon
test/scala/com/avsystem/commons/hocon
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
2
2
package hocon
3
3
4
4
import 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
6
8
import com .typesafe .config .{ConfigValue , ConfigValueFactory }
7
9
8
10
object HoconOutput {
@@ -31,7 +33,14 @@ class HoconOutput(consumer: ConfigValue => Unit) extends OutputAndSimpleOutput {
31
33
def writeList (): HoconListOutput = new HoconListOutput (consumer)
32
34
def writeObject (): HoconObjectOutput = new HoconObjectOutput (consumer)
33
35
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
+ }
35
44
}
36
45
37
46
class HoconListOutput (consumer : ConfigValue => Unit ) extends ListOutput {
Original file line number Diff line number Diff line change 1
1
package com .avsystem .commons
2
2
package hocon
3
3
4
+ import com .avsystem .commons .hocon .HoconInputTest .CustomCodecsClass
4
5
import 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 .*
6
10
7
11
class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {
8
12
type Raw = ConfigValue
@@ -15,4 +19,17 @@ class HoconGenCodecRoundtripTest extends GenCodecRoundtripTest {
15
19
16
20
def createInput (raw : ConfigValue ): Input =
17
21
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
+ }
18
35
}
You can’t perform that action at this time.
0 commit comments