Mojang / DataFixerUpper

A set of utilities designed for incremental building, merging and optimization of data transformations.
MIT License
1.2k stars 138 forks source link

Fix Dynamic.convert() turning Gson boolean primitives into false #42

Closed Juuxel closed 4 years ago

Juuxel commented 5 years ago

Dynamic.convert() checks the number values of the types that are converted, but JsonOps didn't provide a number value for booleans. convert() defaults to 0 (false), so Gson booleans were always false.

Edit: Here's an example of the behavior:

// Different instances so convert() doesn't no-op
JsonOps ops1 = new JsonOps() {};
JsonOps ops2 = new JsonOps() {};
JsonElement converted = Dynamic.convert(ops1, ops2, new JsonPrimitive(true));
System.out.println(converted);
// prints false
boq commented 5 years ago

No test case needed, noticed that problem last week, haven't got around to make my own PR. Though I wanted to add Optional<Boolean> getBooleanValue(T input); to both DynamicOps (default, going through getNumberValue) and JsonOps.

Juuxel commented 5 years ago

Hm, I thought about that as well but didn't really want to make changes to DynamicOps. I can add that to the PR.

msftclas commented 5 years ago

CLA assistant check
All CLA requirements met.

liach commented 4 years ago

Finally, thanks fry!