json-as 1.1.15 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## 2025-06-17 - 1.1.17
4
+
5
+ - fix: add support for classes within namespaces [#147](https://github.com/JairusSW/json-as/pull/147)
6
+
7
+ ## 2025-06-12 - 1.1.16
8
+
9
+ - tests: properly support nulls (in testing lib)
10
+ - fix: initialize generic properties correctly
11
+ - fix: make generated imports compatible with windows
12
+ - feat: add support for fields marked with `readonly`
13
+
3
14
  ## 2025-06-09 - 1.1.15
4
15
 
5
16
  - feat: add `.as<T>()` method to `JSON.Value`
@@ -7,8 +18,6 @@
7
18
  - feat: add support for `StaticArray` serialization
8
19
  - feat: support `JSON.Raw` in array types
9
20
  - tests: add tests for `JSON.Raw[]`
10
- - tests: properly support nulls (in testing lib)
11
- - fix: initialize generic properties correctly
12
21
 
13
22
  ## 2025-05-29 - 1.1.14
14
23
 
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
7
7
  █████ ███████ ██████ ██ ████ ██ ██ ███████
8
8
  </span>
9
- AssemblyScript - v1.1.15
9
+ AssemblyScript - v1.1.17
10
10
  </pre>
11
11
  </h6>
12
12
 
@@ -59,7 +59,6 @@ If you'd like to see the code that the transform generates, run the build step w
59
59
  ```typescript
60
60
  import { JSON } from "json-as";
61
61
 
62
-
63
62
  @json
64
63
  class Vec3 {
65
64
  x: f32 = 0.0;
@@ -67,7 +66,6 @@ class Vec3 {
67
66
  z: f32 = 0.0;
68
67
  }
69
68
 
70
-
71
69
  @json
72
70
  class Player {
73
71
  @alias("first name")
@@ -113,7 +111,6 @@ This library allows selective omission of fields during serialization using the
113
111
  This decorator excludes a field from serialization entirely.
114
112
 
115
113
  ```typescript
116
-
117
114
  @json
118
115
  class Example {
119
116
  name!: string;
@@ -133,7 +130,6 @@ console.log(JSON.stringify(obj)); // { "name": "Jairus" }
133
130
  This decorator omits a field only if its value is null.
134
131
 
135
132
  ```typescript
136
-
137
133
  @json
138
134
  class Example {
139
135
  name!: string;
@@ -153,7 +149,6 @@ console.log(JSON.stringify(obj)); // { "name": "Jairus" }
153
149
  This decorator omits a field based on a custom predicate function.
154
150
 
155
151
  ```typescript
156
-
157
152
  @json
158
153
  class Example {
159
154
  name!: string;
@@ -181,7 +176,6 @@ AssemblyScript doesn't support using nullable primitive types, so instead, json-
181
176
  For example, this schema won't compile in AssemblyScript:
182
177
 
183
178
  ```typescript
184
-
185
179
  @json
186
180
  class Person {
187
181
  name!: string;
@@ -192,7 +186,6 @@ class Person {
192
186
  Instead, use `JSON.Box` to allow nullable primitives:
193
187
 
194
188
  ```typescript
195
-
196
189
  @json
197
190
  class Person {
198
191
  name: string;
@@ -255,7 +248,6 @@ More often, objects will be completely statically typed except for one or two va
255
248
  In such cases, `JSON.Value` can be used to handle fields that may hold different types at runtime.
256
249
 
257
250
  ```typescript
258
-
259
251
  @json
260
252
  class DynamicObj {
261
253
  id: i32 = 0;
@@ -329,7 +321,6 @@ Here's an example of creating a custom data type called `Point` which serializes
329
321
  ```typescript
330
322
  import { bytes } from "json-as/assembly/util";
331
323
 
332
-
333
324
  @json
334
325
  class Point {
335
326
  x: f64 = 0.0;
@@ -0,0 +1,63 @@
1
+ import { JSON } from "..";
2
+ import { describe, expect } from "./lib";
3
+
4
+ describe("Should serialize namespaced derived structs", () => {
5
+ const obj: Namespace.DerivedObject = { a: "foo", b: "bar" };
6
+ expect(JSON.stringify(obj)).toBe(`{"a":"foo","b":"bar"}`);
7
+ });
8
+
9
+ describe("Should serialize namespaced derived structs with nested object", () => {
10
+ const bar: Namespace.Bar = { value: "baz" };
11
+ const obj: Namespace.DerivedObjectWithNestedObject = { a: "foo", b: "bar", c: bar };
12
+ expect(JSON.stringify(obj)).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
13
+ });
14
+
15
+ describe("Should deserialize namespaced object with alias property", () => {
16
+ expect(JSON.stringify(JSON.parse<Namespace.ObjectWithAliasProperty>(`{"a":"foo","value":42}`))).toBe(`{"a":"foo","value":42}`);
17
+ });
18
+
19
+ describe("Should deserialize namespaced derived structs", () => {
20
+ expect(JSON.stringify(JSON.parse<Namespace.DerivedObject>(`{"a":"foo","b":"bar"}`))).toBe(`{"a":"foo","b":"bar"}`);
21
+ expect(JSON.stringify(JSON.parse<Namespace.DerivedObject>(`{"b":"bar","a":"foo"}`))).toBe(`{"a":"foo","b":"bar"}`);
22
+ });
23
+
24
+ describe("Should deserialize namespaced derived structs with nested object", () => {
25
+ expect(JSON.stringify(JSON.parse<Namespace.DerivedObjectWithNestedObject>(`{"a":"foo","b":"bar","c":{"value":"baz"}}`))).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
26
+ expect(JSON.stringify(JSON.parse<Namespace.DerivedObjectWithNestedObject>(`{"c":{"value":"baz"},"a":"foo","b":"bar"}`))).toBe(`{"a":"foo","b":"bar","c":{"value":"baz"}}`);
27
+ });
28
+
29
+ type NumberAlias = i64;
30
+
31
+ namespace Namespace {
32
+
33
+ @json
34
+ export class Base {
35
+ a: string = "";
36
+ }
37
+
38
+
39
+ @json
40
+ export class Bar {
41
+ value: string = "";
42
+ }
43
+
44
+
45
+ @json
46
+ export class ObjectWithAliasProperty {
47
+ a: string = "";
48
+ value: NumberAlias = 0;
49
+ }
50
+
51
+
52
+ @json
53
+ export class DerivedObject extends Base {
54
+ b: string = "";
55
+ }
56
+
57
+
58
+ @json
59
+ export class DerivedObjectWithNestedObject extends Base {
60
+ b: string = "";
61
+ c: Bar = new Bar();
62
+ }
63
+ }