Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package prerna.util;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.burt.jmespath.Expression;
import io.burt.jmespath.JmesPath;
import io.burt.jmespath.jackson.JacksonRuntime;
public class BeanFiller {
protected static final Logger classLogger = LogManager.getLogger(BeanFiller.class);
// takes the data that is coming in from the json
// gets a list of properties
// and then fills it
private static ObjectMapper mapper = new ObjectMapper();
private static JmesPath jmespath = new JacksonRuntime();
private BeanFiller() {
}
// get the jsonNode for input
public static JsonNode getJmesResult(String json, String jsonPattern) {
try {
Expression expression = jmespath.compile(jsonPattern);
JsonNode input = mapper.readTree(json);
JsonNode result = expression.search(input);
return result;
} catch(Exception ex) {
classLogger.error(Constants.STACKTRACE, ex);
}
return null;
}
// fills a single bean
public static Object fillFromJson(String json, String jsonPattern, String [] beanProps, Object bean) {
// make the class
Object retObject = null;
try {
Expression expression = jmespath.compile(jsonPattern);
//AccessToken tok = mapper.readValue(json, AccessToken.class);
JsonNode input = mapper.readTree(json);
JsonNode result = expression.search(input);
if((result instanceof ArrayNode) && result.get(0) instanceof ObjectNode) {
// this is a multiple value
List