opened
vojtechhabarta
username_0
typescript-generator by default generates interfaces from Java classes. It is also able to generate TypeScript classes but when you parse JSON data parsed objects are not instances of these classes. For single object this could be solved by assigning prototype to this object but for object tree this is not sufficient. So typescript-generator will be able to generate **copy** methods which could be used to create deep copy of object tree with correct classes.

Once data can be deserialized to instances of classes it will make sense to have some additional methods on those classes and use them with parsed JSON data. This feature originated in request to have an extension to generate `hashCode`/`equals` methods (#168) but having instances of classes is useful not only when some methods are generated but methods could also be added later by user (added to class prototypes).

There is an `JsonDeserializationTest` for this feature but since this is still WiP (in _master_ branch) this test doesn't fail on differences between expected and actually produced output. Instead the expected and actual outputs are in files so it is possible to view diff for example like this: `code --reuse-window --diff typescript-generator-core\src\test\resources\cz\habarta\typescript\generator\JsonDeserializationTest-expected.ts typescript-generator-core\target\JsonDeserializationTest-actual.ts`.

- [x] unit test
- [x] experimental settings flag
- [x] `fromData` method
- [x] handle undefined and null
- [x] assign simple values, enums
- [ ] inheritance (call super, do not assign inherited properties in derived object again)
- [ ] copy classes using `fromData` method
- [ ] copy arrays (lists) and objects (maps)
- [ ] helper functions
- [ ] discriminated union types
    - generate `fromDataUnion` method
    - use this method
- [ ] generics
    - constructor functions for generic parameters in `fromData` method
    - pass constructor functions at call site
- [ ] test it with `mapPackagesToNamespaces`
- [ ] use JSON deserialization in REST client
- [ ] configuration parameters (enable feature in build plugins)
- [ ] interfaces/classes mix
JSON data deserialization to classes using copy methods
issue
closed
vojtechhabarta
username_0
issue
created
vojtechhabarta
username_0
Released [v1.30.381](https://github.com/username_0/typescript-generator/releases/tag/v1.30.381).
comment