Skip to content

Commit 5c931f5

Browse files
authored
use serialization.createFlavor when available (#119)
For better forward compat with changes in nim-serialization, such as status-im/nim-serialization#84
1 parent 991bd85 commit 5c931f5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

json_serialization/format.nim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import
1111
serialization/[formats, object_serialization]
1212

13-
export
14-
formats
13+
export formats
1514

1615
serializationFormat Json,
1716
mimeType = "application/json"
@@ -60,12 +59,15 @@ template createJsonFlavor*(FlavorName: untyped,
6059
omitOptionalFields = true,
6160
allowUnknownFields = true,
6261
skipNullFields = false) {.dirty.} =
63-
type FlavorName* = object
62+
when declared(SerializationFormat): # Earlier versions lack mimeTypeValue
63+
createFlavor(Json, FlavorName, mimeTypeValue)
64+
else:
65+
type FlavorName* = object
6466

65-
template Reader*(T: type FlavorName): type = Reader(Json, FlavorName)
66-
template Writer*(T: type FlavorName): type = Writer(Json, FlavorName)
67-
template PreferredOutputType*(T: type FlavorName): type = string
68-
template mimeType*(T: type FlavorName): string = mimeTypeValue
67+
template Reader*(T: type FlavorName): type = Reader(Json, FlavorName)
68+
template Writer*(T: type FlavorName): type = Writer(Json, FlavorName)
69+
template PreferredOutputType*(T: type FlavorName): type = string
70+
template mimeType*(T: type FlavorName): string = mimeTypeValue
6971

7072
template flavorUsesAutomaticObjectSerialization*(T: type FlavorName): bool = automaticObjectSerialization
7173
template flavorOmitsOptionalFields*(T: type FlavorName): bool = omitOptionalFields

0 commit comments

Comments
 (0)