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

Enum: argumentless constructors don't seem to work #28

Closed
sh-dave opened this issue Jun 26, 2017 · 3 comments
Closed

Enum: argumentless constructors don't seem to work #28

sh-dave opened this issue Jun 26, 2017 · 3 comments

Comments

@sh-dave
Copy link
Contributor

sh-dave commented Jun 26, 2017

i'm using tink_json 0.6.2 from haxelib

enum Component {
  @:json({ type: 'Transform' }) Transform( x: Float, y: Float );
  @:json('Borked') Borked;
}

class Main {
  public static function main() {
    var data = '[
      { "type": "Transform", "x": 12.3, "y": 45.6 },
      { "type": "Borked" }
    ]';

    var stuff: Array<Component> = tink.Json.parse(data);
    trace(stuff);
  }
}
d:\projects\tink_json_enum_test\index.js:2403 throw new js__$Boot_HaxeError(
new tink_core_TypedError(
  422,
  "Cannot process " + Std.string(__ret), { 
    fileName : "GenReader.hx",
    lineNumber : 291,
    className : "tink.json.Parser0", methodName : "parse0"
  }
));
                                ^
Error: Error#422: Cannot process {
        type : Borked,
        x : null,
        y : null
} @ tink.json.Parser0.parse0:291
    at tink_json_Parser0.parse0 (d:\projects\tink_json_enum\index.js:2403:11)
    at tink_json_Parser0.parse (d:\projects\tink_json_enum\index.js:2551:21)
    at Function.Main.main (d:\projects\tink_json_enum\index.js:45:38)
    at d:\projects\tink_json_enum\index.js:2627:6
    at Object.<anonymous> (d:\projects\tink_json_enum\index.js:2628:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
@back2dos
Copy link
Member

Ok, the error quite useless ^^

The solution would be to align @:json('Borked') Borked; and { "type": "Borked" }, i.e. either declare @:json({ type: 'Borked'}) Borked; or parse "Borked".

@sh-dave
Copy link
Contributor Author

sh-dave commented Jun 26, 2017

@:json({ type: 'Borked' }) Borked; results in a compilation error

Main.hx:3: characters 28-35 : invalid use of @:json.

It was actually the first thing i did, only then changed it to the current form b/c it says so in the docs https://github.com/haxetink/tink_json/blame/master/README.md#L86

@kevinresol
Copy link
Member

kevinresol commented Jun 26, 2017

enum Component {
  @:json({ type: 'Transform' }) Transform( x: Float, y: Float );
  @:json('Borked') Borked;
}

class Main {
  public static function main() {
    var data = '[
      { "type": "Transform", "x": 12.3, "y": 45.6 },
      "Borked"
    ]';

    var stuff: Array<Component> = tink.Json.parse(data);
    trace(stuff);
  }
}

@back2dos means changing your data. But yes something should be done with @:json({type: 'Borked'})

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

No branches or pull requests

3 participants