Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

JsonSerializer - Is it possible to instantiate a class by constructor params? #5

Open
natami opened this issue Aug 9, 2014 · 1 comment

Comments

@natami
Copy link

natami commented Aug 9, 2014

Is it possible to instantiate a class by constructor params, and how?

like:

public class TestClass {

private var _test:String;

private var _innerTestClass:InnerTestClass;

public function TestClass(test:String, innerTestClass:InnerTestClass) {
    _test = test;
    _innerTestClass = innerTestClass;
}


public function get test():String {
    return _test;
}


public function get innerTestClass():InnerTestClass {
    return _innerTestClass;
}

}

public class InnerTestClass {
private var _innerString:String;

public function InnerTestClass(innerString:String) {
    this._innerString = innerString;
}


public function get innerString():String {
    return _innerString;
}

}

@nexussays
Copy link
Owner

There is not currently any method to invoke parametrized constructors.

If you're using this for serialization, I would advise to create a separate class as a transfer object. It both eases the de/serialization process and makes the resulting JSON/XML/etc simpler.

Alternately you could use namespaces (see: http://gskinner.com/blog/archives/2010/01/a_complete_guid.html) to hide the setters in your classes and I think the serializer and deserializer respect them. I know I did that one one project but I don't recall whether or not I had to write code in addition to what's in this library to make it work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants