Cannot serliaze table with recursive entities
SirEdvin opened this issue · 3 comments
Minecraft Version
1.20.x
Version
1.108
Details
It seems, it is impossible to serialize table, that contains several instances of another table.
For example, like here:
local empty_table = {}
local big_table = {empty_table, empty_table}
print(textutils.serializeJSON(big_table))
But itself it probably fine, but with combination different minecraft addons, that usually use Collections.emptyList
or something like this to return empty values, this leads to strange issues, when table, that are purely serializable at first glance, turns out to be not serializable.
I believe, or empty tables should be excluded from this rule, or Java -> Lua transformation should always create new table for empty table.
I'm not really sure there's a sensible and disciplined way to "fix" this. As I've mentioned elsewhere (i.e. #1368), I really want textutils.unserialise(textutils.serialise(x))
to return an equivalent table, and so excluding empty tables from this check is a bit silly. Similarly, special-casing any empty collection on the Java side is wrong.
We could special-case some of the known empty collections (List.of()
, Collections.emptyList()
, and their set and map equivalents), but this feels ugly.
As an aside, one can pass { allow_repetitions = true }
to the serialise function to prevent this error.