jf3096/json-typescript-mapper

ZoneAwareError

bunnywrote opened this issue · 2 comments

I try to deserialize json like this:

deserialize(Event, json);

but get the follow error:

Error: Cannot resolve all parameters for 'Parser'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Parser' is decorated with Injectable

what i'm doing wrong?

could you send me your code or create a demo to reproduce the error?

I'm getting the same error.

class Book {
  title: string;

  getTitle(): string {
    return this.title;
  }
}
let b = deserialize(Book, {"title": "JS for Dummy"});
console.log('b', b);

I think this error not actually happens during deserialize code execution, but happens as soon as I access the website (angular-cli created project).

If I remove deserialize() statement, and all the @JsonProperty() decorator, this error is gone. But as soon as I put one decorator, the error comes back again even if there is no deserialize code at all.

Interestingly I tried several other similar libraries eg. json2typescript, class-transformer ,and I got the same error for them. I guess there is something wrong with my project itself, but I just can't figure out what it is.

Update
I just created a new project by using angular-cli, then imported only this package. It's the same error.

Error: Cannot resolve all parameters for 'Parser'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Parser' is decorated with Injectable.
    at NoAnnotationError.ZoneAwareError (http://localhost:4200/polyfills.bundle.js:3270:33)
    at NoAnnotationError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:24961:16)
    at new NoAnnotationError (http://localhost:4200/vendor.bundle.js:53210:16)
    at _dependenciesFor (http://localhost:4200/vendor.bundle.js:38187:15)
    at resolveReflectiveFactory (http://localhost:4200/vendor.bundle.js:38066:24)
    at resolveReflectiveProvider (http://localhost:4200/vendor.bundle.js:38091:139)
    at Array.map (native)
    at resolveReflectiveProviders (http://localhost:4200/vendor.bundle.js:38100:48)
    at Function.ReflectiveInjector.resolve (http://localhost:4200/vendor.bundle.js:70922:127)
    at Function.ReflectiveInjector.resolveAndCreate (http://localhost:4200/vendor.bundle.js:70955:79)
    at JitCompilerFactory.createCompiler (http://localhost:4200/vendor.bundle.js:65282:117)
    at PlatformRef_._bootstrapModuleWithZone (http://localhost:4200/vendor.bundle.js:36321:57)
    at PlatformRef_.bootstrapModule (http://localhost:4200/vendor.bundle.js:36308:21)
    at Object.322 (http://localhost:4200/main.bundle.js:33:124)
    at __webpack_require__ (http://localhost:4200/inline.bundle.js:53:30)

I think it might be some incompatibility issue with the new version of TypeScript. Really hope it can be sorted out.

Environment
@angular/cli: 1.0.0-beta.31
node: 6.9.1
os: darwin x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-beta.31
@angular/compiler-cli: 2.4.9