All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.diff.utils.JacksonHelperUtil Maven / Gradle / Ivy

The newest version!
package com.arextest.diff.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by rchen9 on 2023/2/16.
 */
public class JacksonHelperUtil {

  public static ObjectMapper objectMapper = new ObjectMapper();

  public static List getNames(ObjectNode objectNode) {
    List result = new ArrayList<>();
    Iterator stringIterator = objectNode.fieldNames();
    while (stringIterator.hasNext()) {
      result.add(stringIterator.next());
    }
    return result;
  }

  public static ObjectNode getObjectNode() {
    return objectMapper.createObjectNode();
  }

  public static ArrayNode getArrayNode() {
    return objectMapper.createArrayNode();
  }

  public static boolean isObjectNode(Object object) {
    return object instanceof ObjectNode;
  }

  public static boolean isArrayNode(Object object) {
    return object instanceof ArrayNode;
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy