Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
映射的ArrayNode等价物,Java_Java_Json_Serialization - Fatal编程技术网

映射的ArrayNode等价物,Java

映射的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

使用json反序列化时,是否有一个等效的“ArrayNode”用于映射

我想重用这个代码

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;
}