映射的ArrayNode等价物,Java
使用json反序列化时,是否有一个等效的“ArrayNode”用于映射 我想重用这个代码映射的ArrayNode等价物,Java,java,json,serialization,Java,Json,Serialization,使用json反序列化时,是否有一个等效的“ArrayNode”用于映射 我想重用这个代码 if (menuNode instanceof ArrayNode) 在我的目标上。菜单objekt包含一个数组,但disps对象包含一个映射(hashmap)。所以我想要像这样的东西 if (allDisheshNode instanceof MapNode) 但这是行不通的。有没有办法做到这一点?这是整个方法: public AllDishes deserialize(JsonParser p, D
if (menuNode instanceof ArrayNode)
在我的目标上。菜单objekt包含一个数组,但disps对象包含一个映射(hashmap)。所以我想要像这样的东西
if (allDisheshNode instanceof MapNode)
但这是行不通的。有没有办法做到这一点?这是整个方法:
public AllDishes deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
TreeNode treeNode = p.getCodec().readTree(p);
if (treeNode instanceof ObjectNode) {
ObjectNode objectNode = (ObjectNode) treeNode;
AllDishes allDishes = new AllDishes();
JsonNode allDishesNode = objectNode.get("dishMap");
if (allDishesNode instanceof MapNode) {
for (JsonNode node : ((MapNode) allDishesNode)) {
Dish dish = dishDes.deserialize(node); //Reads the names from json-file and makes the into Dish-objects
if (dish != null) {
allDishes.addUserDish(dish);
}
}
}
return allDishes;
}
return null;
}