Open Gaming32 opened 1 year ago
I was actually planning to add mutable versions when I originally started designing the API. I decided against it and probably won't because I'm trying to closely mirror kotlinx.serialization's API. JsonElement, for example
If they ever do add mutable versions (and it might be worth opening an issue/discussion about it) then 100% I'll add those right in!
What's your use case for them? I can think of a few possible alternatives, depending on what you're trying to do.
My use case is using NBT data similar to how Minecraft uses NBT data. Notably, ItemStack
mutates the item data NBT. I was able to make my thing work by creating a second set of classes (one for each NbtTag
subclass) that are mutable and can be converted to and from NbtTag
. However creating a mutable deep copy doesn't feel like the best way.
Also, yes, JsonElement
is immutable. I do think that JSON isn't modified directly as much though, as it's usually used purely for serialization. NBT, on the other hand, is often used to store arbitrary dynamic data that has less of a static format.
It would be extremely useful to have data structure-based tags (such as
NbtCompound
) be mutable.