Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic object array support #3

Open
pyunghwa opened this issue Apr 27, 2019 · 3 comments
Open

Polymorphic object array support #3

pyunghwa opened this issue Apr 27, 2019 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@pyunghwa
Copy link

Hi! I have one more question.
Does it support polymorphic object array to mapping? If supported, how to do? If not, any plan?

@pverscha pverscha self-assigned this Apr 27, 2019
@pverscha pverscha added the question Further information is requested label Apr 27, 2019
@pverscha
Copy link
Member

pverscha commented Apr 27, 2019

Hi Chris,

The package currently supports mapping of arrays with custom objects, like this:

@ReadArray(MyCustomObject)
@UpdateArray(MyCustomObject)
@StoreArray(MyCustomObject)
private _data: MyCustomObject[];

At this moment it's however not possible to pass objects that inherit from MyCustomObject without changing the signature of the decorators, due to limitations posed by the reflection metadata in TypeScript. Can you give me an example of what you're trying to achieve?

Thanks!

@pyunghwa
Copy link
Author

pyunghwa commented Apr 29, 2019

Hi, @pverscha :)
My case is to pass objects that inherit from specified object.

Like this.

class Part {
}
class RoofPart extends Part {
}
class ColumnPart extends Part {
}
class FloorPart extends Part {
}
 :
class All {
  part: Part[] = [
    new RoofPart(),
    new ColumnPart(),
    new FloorPart()
    :
  ];
}

This RoofPart, ColumnPart, FloorPart and so on have different variables and functions.
Do you plan to support polymorphic object array?

If so, please refer.. I looked into some package that support polymorphic object array. These are just mapping Json to Typescript.

  1. json2typescript : supports Custom converter, like this answer https://stackoverflow.com/questions/46601348/json-to-typescript-object-inheritance
    But, this package is too, too slow.

  2. TypedJSON : supports polymorphic behavior by Json data added class delimiter(__type) and class annotations.
    How to achieve polymorphic behavior? JohnWeisz/TypedJSON#88
    Example code is https://github.com/JohnWeisz/TypedJSON/blob/master/spec/polymorphism.spec.ts
    It has to add class delimiter into Json data, and the annotation for polymorphic objects is located strangely.

Thanks.

@pverscha
Copy link
Member

pverscha commented May 4, 2019

Hi Chris,

Sorry for the delay in getting back to you. I try to take a look at this today or tomorrow and implement some of the required features if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants