Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1035334 // test_structure_customSerializer (_serialize and _deserialize methods)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13113L/76K).

1  
scope test_structure_customSerializer
2  
3  
sclass #X {
4  
  settable int i;
5  
  
6  
  // _serialize can now return this to request standard serialization
7  
  O _serialize() {
8  
    ret i < 0 ? this : i;
9  
  }
10  
  
11  
  static X _deserialize(O o) {
12  
    ret new X().i((int) o);
13  
  }
14  
  
15  
  [stdEq]
16  
}
17  
18  
svoid test_structure_customSerializer() {
19  
  X x = new X().i(5);
20  
  S s = struct(x);
21  
  S nameOfX = shortClassName(X);
22  
  assertEqualsVerbose("cu " + nameOfX + " 5", s);
23  
  assertEqualsVerbose(x, unstructure(s));
24  
  
25  
  x = new X().i(-5);
26  
  s = print(struct(x));
27  
  assertEqualsVerbose(x, unstructure(s));
28  
}

Author comment

Began life as a copy of #1035332

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035334
Snippet name: test_structure_customSerializer (_serialize and _deserialize methods)
Eternal ID of this version: #1035334/6
Text MD5: e99648629ccf785646c97062fb5c2c1b
Transpilation MD5: b871fe361259c69fdd201668094b3888
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-01 17:31:57
Source code size: 599 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 77 / 136
Version history: 5 change(s)
Referenced in: [show references]