diff --git a/README.md b/README.md index 605ec84..efbb5da 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ First, install [deser](https://github.com/gabbhack/deser) via `nimble install deser` deser_json provides three procedures: -1. `toString` for serialization -1. `toPrettyString` for pretty serialization -1. `fromString` for deserialization +1. `toJson` for serialization +1. `toPrettyJson` for pretty serialization +1. `fromJson` for deserialization ```nim import @@ -26,9 +26,9 @@ import var some = [1, 2, 3] -echo some.toString() +echo some.toJson() -some = fromString(typeof(some), "[1, 2, 3]") +some = fromJson(typeof(some), "[1, 2, 3]") ``` See the [deser documentation](https://deser.nim.town/deser.html) for a complete example. diff --git a/src/deser_json/des.nim b/src/deser_json/des.nim index 8502dc6..da6e5f0 100644 --- a/src/deser_json/des.nim +++ b/src/deser_json/des.nim @@ -3,13 +3,13 @@ import des/des export des -func fromString*(Self: typedesc, input: sink string): Self {.inline.} = ##[ +func fromJson*(Self: typedesc, input: sink string): Self {.inline.} = ##[ Deserialize your type from string. Accepts only type that implement `deserialize` procedure. ]## runnableExamples: import deser - let integer = int.fromString("123") + let integer = int.fromJson("123") assert integer == 123 mixin deserialize diff --git a/src/deser_json/ser.nim b/src/deser_json/ser.nim index 80f4afb..af1e5ca 100644 --- a/src/deser_json/ser.nim +++ b/src/deser_json/ser.nim @@ -8,13 +8,13 @@ export formatter -func toString*(value: auto): string {.inline.} = ##[ +func toJson*(value: auto): string {.inline.} = ##[ Serialize your value to string. Accepts only type that implement `serialize` procedure. ]## runnableExamples: import deser - let str = 123.toString() + let str = 123.toJson() assert str == "123" mixin serialize @@ -24,13 +24,13 @@ Serialize your value to string. Accepts only type that implement `serialize` pro result = ser.writer -func toPrettyString*(value: auto): string {.inline.} = ##[ +func toPrettyJson*(value: auto): string {.inline.} = ##[ Serialize your value to pretty string. Accepts only type that implement `serialize` procedure. ]## runnableExamples: import deser - let str = 123.toPrettyString() + let str = 123.toPrettyJson() assert str == "123" mixin serialize diff --git a/tests/des/tdes.nim b/tests/des/tdes.nim index 975b982..b23f323 100644 --- a/tests/des/tdes.nim +++ b/tests/des/tdes.nim @@ -21,67 +21,67 @@ makeDeserializable(Struct) suite "serialize": test "bool": - doAssert true == bool.fromString("true") - doAssert false == bool.fromString("false") + doAssert true == bool.fromJson("true") + doAssert false == bool.fromJson("false") test "int": - doAssert 123 == int.fromString("123") - doAssert 123i8 == int8.fromString("123") - doAssert 123i16 == int16.fromString("123") - doAssert 123i32 == int32.fromString("123") - doAssert 123i64 == int64.fromString("123") + doAssert 123 == int.fromJson("123") + doAssert 123i8 == int8.fromJson("123") + doAssert 123i16 == int16.fromJson("123") + doAssert 123i32 == int32.fromJson("123") + doAssert 123i64 == int64.fromJson("123") - doAssert 123.uint == uint.fromString("123") - doAssert 123u8 == uint8.fromString("123") - doAssert 123u16 == uint16.fromString("123") - doAssert 123u32 == uint32.fromString("123") - doAssert 123u64 == uint64.fromString("123") + doAssert 123.uint == uint.fromJson("123") + doAssert 123u8 == uint8.fromJson("123") + doAssert 123u16 == uint16.fromJson("123") + doAssert 123u32 == uint32.fromJson("123") + doAssert 123u64 == uint64.fromJson("123") test "float": - doAssert 123.0 == float.fromString("123.0") - doAssert 123.0f32 == float32.fromString("123.0") - doAssert 123.0f64 == float64.fromString("123.0") + doAssert 123.0 == float.fromJson("123.0") + doAssert 123.0f32 == float32.fromJson("123.0") + doAssert 123.0f64 == float64.fromJson("123.0") test "string": - doAssert "123" == string.fromString("\"123\"") + doAssert "123" == string.fromJson("\"123\"") test "char": - doAssert '1' == char.fromString("\"1\"") + doAssert '1' == char.fromJson("\"1\"") test "bytes": - doAssert ['0'.byte, '1'.byte] == fromString(array[2, byte], "[48,49]") + doAssert ['0'.byte, '1'.byte] == fromJson(array[2, byte], "[48,49]") test "none": - doAssert none[int]() == fromString(Option[int], "null") + doAssert none[int]() == fromJson(Option[int], "null") test "some": - doAssert some(123) == fromString(Option[int], "123") + doAssert some(123) == fromJson(Option[int], "123") test "array": - doAssert [1,2,3] == fromString(array[3, int], "[1,2,3]") + doAssert [1,2,3] == fromJson(array[3, int], "[1,2,3]") test "seq": - doAssert @[1,2,3] == fromString(seq[int], "[1,2,3]") + doAssert @[1,2,3] == fromJson(seq[int], "[1,2,3]") test "tuple": - doAssert (1,2,3) == fromString((int, int, int), "[1,2,3]") + doAssert (1,2,3) == fromJson((int, int, int), "[1,2,3]") test "named tuple": - doAssert (id: 123, text: "123") == fromString(tuple[id: int, text: string], "[123,\"123\"]") + doAssert (id: 123, text: "123") == fromJson(tuple[id: int, text: string], "[123,\"123\"]") test "map": - doAssert {"text": "123"}.toTable == fromString(Table[string, string], "{\"text\":\"123\"}") + doAssert {"text": "123"}.toTable == fromJson(Table[string, string], "{\"text\":\"123\"}") test "struct": - doAssert Struct(id: 123, text: "123") == Struct.fromString("{\"id\":123,\"text\":\"123\"}") + doAssert Struct(id: 123, text: "123") == Struct.fromJson("{\"id\":123,\"text\":\"123\"}") test "enum": type Foo = enum First = "first" - doAssert First == Foo.fromString("\"first\"") + doAssert First == Foo.fromJson("\"first\"") type Bar = enum Second - doAssert Second == Bar.fromString("\"Second\"") + doAssert Second == Bar.fromJson("\"Second\"") diff --git a/tests/ser/tser.nim b/tests/ser/tser.nim index c40ddae..39e98c1 100644 --- a/tests/ser/tser.nim +++ b/tests/ser/tser.nim @@ -21,66 +21,66 @@ makeSerializable(Struct) suite "serialize": test "bool": - doAssert ser.toString(true) == "true" - doAssert ser.toString(false) == "false" + doAssert ser.toJson(true) == "true" + doAssert ser.toJson(false) == "false" test "int": - doAssert ser.toString(123) == "123" - doAssert ser.toString(123i8) == "123" - doAssert ser.toString(123i16) == "123" - doAssert ser.toString(123i32) == "123" - doAssert ser.toString(123i64) == "123" + doAssert ser.toJson(123) == "123" + doAssert ser.toJson(123i8) == "123" + doAssert ser.toJson(123i16) == "123" + doAssert ser.toJson(123i32) == "123" + doAssert ser.toJson(123i64) == "123" - doAssert ser.toString(123u8) == "123" - doAssert ser.toString(123u16) == "123" - doAssert ser.toString(123u32) == "123" - doAssert ser.toString(123u64) == "123" + doAssert ser.toJson(123u8) == "123" + doAssert ser.toJson(123u16) == "123" + doAssert ser.toJson(123u32) == "123" + doAssert ser.toJson(123u64) == "123" test "float": - doAssert ser.toString(123.0) == "123.0" - doAssert ser.toString(123.0f32) == "123.0" - doAssert ser.toString(123.0f64) == "123.0" + doAssert ser.toJson(123.0) == "123.0" + doAssert ser.toJson(123.0f32) == "123.0" + doAssert ser.toJson(123.0f64) == "123.0" test "string": - doAssert ser.toString("123") == "\"123\"" + doAssert ser.toJson("123") == "\"123\"" test "char": - doAssert ser.toString('1') == "\"1\"" + doAssert ser.toJson('1') == "\"1\"" test "bytes": - doAssert ser.toString(['0'.byte, '1'.byte]) == "[48,49]" + doAssert ser.toJson(['0'.byte, '1'.byte]) == "[48,49]" test "none": - doAssert ser.toString(none int) == "null" + doAssert ser.toJson(none int) == "null" test "some": - doAssert ser.toString(some 123) == "123" + doAssert ser.toJson(some 123) == "123" test "array": - doAssert ser.toString([1,2,3]) == "[1,2,3]" + doAssert ser.toJson([1,2,3]) == "[1,2,3]" test "seq": - doAssert ser.toString(@[1,2,3]) == "[1,2,3]" + doAssert ser.toJson(@[1,2,3]) == "[1,2,3]" test "tuple": - doAssert ser.toString((1,2,3)) == "[1,2,3]" + doAssert ser.toJson((1,2,3)) == "[1,2,3]" test "named tuple": - doAssert ser.toString((id: 123, text: "123")) == "[123,\"123\"]" + doAssert ser.toJson((id: 123, text: "123")) == "[123,\"123\"]" test "map": - doAssert ser.toString({"text": "123"}.toTable) == "{\"text\":\"123\"}" + doAssert ser.toJson({"text": "123"}.toTable) == "{\"text\":\"123\"}" test "struct": - doAssert ser.toString(Struct(id: 123, text: "123")) == "{\"id\":123,\"text\":\"123\"}" + doAssert ser.toJson(Struct(id: 123, text: "123")) == "{\"id\":123,\"text\":\"123\"}" test "enum": type Foo = enum First = "first" - doAssert ser.toString(First) == "\"first\"" + doAssert ser.toJson(First) == "\"first\"" type Bar = enum Second - doAssert ser.toString(Second) == "\"Second\"" + doAssert ser.toJson(Second) == "\"Second\""