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

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

There is a newer version: 0.2.15
Show newest version
package com.arextest.diff.utils;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;

public class NameConvertUtil {

  public static void nameConvert(Object object) {
    if (object == null || object instanceof NullNode) {
      return;
    }

    if (object instanceof ObjectNode) {
      ObjectNode jsonObj1 = (ObjectNode) object;
      List names = JacksonHelperUtil.getNames(jsonObj1);

      for (String fieldName : names) {
        JsonNode obj1FieldValue = jsonObj1.get(fieldName);
        String lowerCase = fieldName.toLowerCase();
        jsonObj1.set(lowerCase, obj1FieldValue);
        if (fieldName != lowerCase) {
          jsonObj1.remove(fieldName);
        }
        nameConvert(obj1FieldValue);
      }
    } else if (object instanceof ArrayNode) {
      ArrayNode obj1Array = (ArrayNode) object;
      int len = obj1Array.size();
      for (int i = 0; i < len; i++) {
        Object element = obj1Array.get(i);
        nameConvert(element);
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy