如何在gson中转换现有对象的类型?

时间:2017-02-04 23:58:47

标签: java serialization gson

我收到了这个错误:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was NUMBER at line 636 column 6

我对序列化和gson相当新。我将byte []更改为int [] [],并且遇到问题,因为gson在加载文件时找到旧的byte []而不是int [] []。有没有办法我可以删除甚至排除加载字节[],然后下次保存它将用int [] []替换它?

Pouches是我从byte []更改为int [] []。

这是加载代码:

PlayerContainer details = PlayerSave.GSON.fromJson(reader, PlayerContainer.class);

这是PlayerContainer.class:

    private final Item[] bank;
    private final int[] tabAmounts;
    private final Item[] inventory;
    private final Item[] equipment;
    private final Item[] bobInventory;
    private final Item[] shopItems;
    private final int[] shopPrices;
    private final int[][] pouches;

    public PlayerContainer(Player player) {
        bank = player.getBank().getItems();
        tabAmounts = player.getBank().getTabAmounts();
        inventory = player.getInventory().getItems();
        equipment = player.getEquipment().getItems();
        bobInventory = (player.getSummoning().isFamilarBOB() ? player.getSummoning().getContainer().getItems() : null);
        shopItems = player.getPlayerShop().getItems();
        shopPrices = player.getPlayerShop().getPrices();
        pouches = player.getPouches();
    }

此外,还有这个但它在到达之前就出错了:

if (details.pouches != null) {
                player.setPouches(details.pouches);
            }

0 个答案:

没有答案