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

exception:Too late to register class on cs and java #24

Closed
AdrianV opened this issue Mar 13, 2018 · 3 comments

Comments

@AdrianV
Copy link

commented Mar 13, 2018

I don't know if it is a bug of the cs and java target or of hxbit. But the following code throws an exception on both targets "Too late to register class" at hxbit.Serializer.registerClass()
So I post the issue here.

class SomeBase implements hxbit.Serializable {
	@:s public var name: String = "";
	@:s public var className: String = "";
	@:s public var module: String = "";
	@:s public var headerTAN: Int = 0;

	public function new(name, className, module) {
		this.name = name;
		this.className = className;
		this.module = module;
	}
}

class Person implements hxbit.Serializable {
	@:s public var name: String = "";
	@:s public var age: Int = 0;

	public function new(name, age) {
		this.name = name;
		this.age = age;
	}
}

class SomePerson extends Person {

	public function new(name, age) {
		super(name, age);
	}
}

class Bug {

	static function main() {
		var p = new SomePerson("Adrian", 54);
		var s = new hxbit.Serializer();
		var data = s.serialize(p);
		var test = s.unserialize(data, Person);
		trace(test); 
		var sb = new SomeBase("Hallo", "Haxe", ""); // here it throws
		var data = s.serialize(sb);
		var sb2 = s.unserialize(data, SomeBase);
		trace(sb2);
		
	}
}
@dmitryhryppa

This comment has been minimized.

Copy link

commented Aug 28, 2018

Any updates on this?
Got the similar behaviour on Java target.

class PlaceStruct implements hxbit.Serializable {
    @s public var name:String;
    @s public var address:String;
    
    public function new(name:String, address:String) {
        this.name = name;
        this.address = address;
    }
}

//--------------------------
//Call constructor anywhere:
new PlaceStruct("Name", "Address"); // java.lang.ExceptionInInitializerError

Did I miss something?

@ncannasse

This comment has been minimized.

Copy link
Member

commented Oct 19, 2018

Seems strange, we insert with macros a static var __clid = hxbit.Serializer.registerClass(MyClass) in all classes implementing hxbit.Serializable, which should be called before the Serializer is created.

@waneck what is the status of static var initialization on java output?

@ncannasse

This comment has been minimized.

Copy link
Member

commented Oct 19, 2018

Seems like a Haxe issue, not hxbit specific. Closing this issue for now (follow up on referenced haxe issue)

@ncannasse ncannasse closed this Oct 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.