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

Json Marshaller toModel() stopped working #9622

Open
cajus opened this issue Jan 31, 2019 · 13 comments

Comments

Projects
None yet
2 participants
@cajus
Copy link
Contributor

commented Jan 31, 2019

Describe the bug

When using the Json marshaller to build a model like this:

    var item = {
        info: "foobar",
        read: true
    };

    var jsonMashaller = new qx.data.marshal.Json();
    var modelItem = jsonMashaller.toModel(item);

it internally creates a class named qx.data.model.info|read♥. This class can be obtained by qx.Class.getByName("qx.data.model.info|read♥"). The Json Marshaller thinks, that the class is named qx.Class.getByName("qx.data.model.info|qxOwner|qxObjectId|read♥") and runs into an exception:

qx.data.marshal.Json.prototype.__createInstance() (Json.js:347)
qx.data.marshal.Json.prototype.__toModel() (Json.js:435)
qx.data.marshal.Json.prototype.toModel() (Json.js:383)
wrappedFunction (Interface.js:537)
<snip>

Expected behavior
Well - it should work ;-)

@cajus cajus added the bug label Jan 31, 2019

@johnspackman

This comment has been minimized.

Copy link
Member

commented Feb 3, 2019

I can't reproduce this - the naming is working OK for me, although I had to add a call to toClass for your example to work. I just tried this in the playground:

      var item = {
          info: "foobar",
          read: true
      };

      var jsonMashaller = new qx.data.marshal.Json();
      var clazz = jsonMashaller.toClass(item);
      var modelItem = jsonMashaller.toModel(item);
      console.log("classname=" + modelItem.classname);

console output is:

000269 qx.core.Init: Load runtime: 269ms
playground.js:213 000556 qx.core.Init: Main runtime: 287ms
playground.js:213 000592 qx.core.Init: Finalize runtime: 36ms
playground.js:213 001046 qx.application.Standalone[517-0]: Starting application 'Hello World' ...
playground.js:213 001046 qx.application.Standalone[517-0]: Successfully started.
playground.js:213 007721 qx.application.Standalone[517-0]: Starting application 'Hello World (modified)' ...
VM2452:29 classname=qx.data.model.info|read
playground.js:213 007725 qx.application.Standalone[517-0]: Successfully started.
@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Well. The code is there for about 5 years, it worked fine and it didn't need any toClass() calls before. So there must be something wrong after the addition of the new object ids. If I revert it, it works fine again.

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Additionally toModel() calls toClass() automatically - that's where it fails.

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Just tried with adding "toClass()". Doesn't work either.

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

It starts to break with e966b27

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Setting "module.objectid": false helps.

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Not sure how the playground is configured in the moment, and what version it is built with. This reproduces the problem:

wget https://github.com/qooxdoo/qooxdoo/archive/master.zip
unzip master.zip
qooxdoo-master/tool/bin/create-application.py -n foo

Edit foo/source/class/foo/Application.js to contain the code from the initial bug report.

cd foo && ./generate.py source

Serve it with and without "module.objectid" enabled.

@johnspackman

This comment has been minimized.

Copy link
Member

commented Feb 4, 2019

This is very odd - I've just tried exactly that, copying and pasting your code from above (although I ran ./generate.py clean && ./generate.py source). I've also tried with my usual qooxdoo directory, after git checkout upstream/master.

I get no errors in compilation, just this at runtime:

000222 qx.core.Init: Load runtime: 222ms
Application.js:64 classname=qx.data.model.info|read
foo.d6f36a764ffc.js:290 000949 qx.core.Init: Main runtime: 726ms
foo.d6f36a764ffc.js:290 000994 qx.core.Init: Finalize runtime: 45ms

The documentation for toModel begins:

/**
     * Creates for the given data the needed models. Be sure to have the classes
     * created with {@link #toClass} before calling this method.  [...snip...]

So it seems to be saying that toClass is mandatory, and I cannot find a place in the source where toModel calls toClass automatically.

If I do not add the call to toClass, I get a different error which is:

Json.js:347 Uncaught Error: Class 'qx.data.model.info|read' could not be found.

This seems to be different to the problem you're experiencing, which is that the marshaller is looking for qx.data.model.info|qxOwner|qxObjectId|read♥, whereas in mine it's correctly looking for qx.data.model.info|read, it's just that the class has not been defined yet.

The previous commit seems to be 263f2cc, but I've just tried checking that out and get the same behaviour. Also this confirmed there is no object id mechanism in 263f2cc:

new qx.core.Object().getQxObjectId()
VM4310:1 Uncaught TypeError: (intermediate value).getQxObjectId is not a function
    at <anonymous>:1:22
(anonymous) @ VM4310:1
@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

So what can I do to have it reproducible for you? The above code reproduces it for me on a vanilla, non git way. From a naive point of view, I'd expect the error to be the same on different systems.

@johnspackman

This comment has been minimized.

Copy link
Member

commented Feb 4, 2019

I think that there are some inconsistencies that if we can track them down might get us closer to understanding what's going wrong; for example, you've said that toClass was previously called automatically and e966b27 broke that - except that I can't see anywhere in https://github.com/qooxdoo/qooxdoo/blob/master/framework/source/class/qx/data/marshal/Json.js where this happens -- except in the static createModel method, but you've said that's not what you're using.

That inconsistency makes me wonder if something really weird is going on where an old copy of qooxdoo is somehow being used, and not the one the that you've just downloaded.

Can you get the same results on another machine? I'll try a Windows VM and a Centos box in a minute.

Can you set it up on a VM in the cloud (eg Cloud 9) so that I can log in and try it for myself?

Sorry, not trying to be unhelpful, I'm just running out of options to see whats going on

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Our CI always starts over from scratch. There's no persistent data there, so it's unlikely that there's an old qx version around. Locally the same. I did it in a completely clean directory and the files point to the downloaded qooxdoo-master.

shot

@cajus

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

Whatever the reason is - I'll try to dig into it later after other project stuff is done.

@johnspackman

This comment has been minimized.

Copy link
Member

commented Feb 4, 2019

In that screenshot, it shows that it is qx.data.model.info|read that can't be found, not the qx.data.model.info|qxOwner|qxObjectId|read.

Does your full application not end up calling toClass somehow some other way, before your call to toModel? Eg you're using .createModel somewhere else with an identically signatured JSON object?

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