elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

Parser of Dynamic are not generated (even with jcustomparse) #89

Closed EliteMasterEric closed 1 year ago

EliteMasterEric commented 1 year ago

I'm looking to parse a JSON string, for which one value is a JSON object which can contain any values. I was intending on parsing that object later based on the value of another property.

However, when I try to do this, I get an error:

json2object/reader/DataBuilder.hx:422: characters 27-32 : json2object: Parser of Dynamic are not generated

This occurs even when I do the following:

  @:alias("v")
  @:optional
  @:jcustomparse(package.DataParse.dynamicValue)
  public var value:Dynamic = null;

My expectation here is that the error would be skipped over because a parser has been provided.

I would also expect that, in the general case, Dynamic would just have the parser insert the value without validating types (so if v is a String, just set value to the String, and if it's an object, set it to an anonymous structure like the output of haxe.Json.

elnabo commented 1 year ago

I didn't reproduce with your example.

Could you tell which version of json2object you are using and if possible provide a more complete example ?

This could come from your dynamicValue function if it also use json2object for the parsing.

EliteMasterEric commented 1 year ago

I will produce a more complete test bench, hold on.

EDIT: I get the same error on this repo: https://github.com/EliteMasterEric/json2object-dynamic

elnabo commented 1 year ago

Thanks for the code, I would probably never found the issue otherwise.

For some reason the type of the Dynamic field changes when it has an initial value.

With the latest commit, it should work for you.

EliteMasterEric commented 1 year ago

Oh yeah this is fixed.