Tabnine Logo
JSONUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
JSONUtils
in
org.apache.metron.stellar.common.utils

Best Java code snippets using org.apache.metron.stellar.common.utils.JSONUtils (Showing top 16 results out of 315)

origin: apache/metron

/**
 * Fetches the global configuration from Zookeeper.
 * @param zkClient The Zookeeper client.
 * @return The global configuration retrieved from Zookeeper.
 * @throws Exception
 */
private Map<String, Object> fetchGlobalConfig(CuratorFramework zkClient) throws Exception {
 byte[] raw = readGlobalConfigBytesFromZookeeper(zkClient);
 return JSONUtils.INSTANCE.load( new ByteArrayInputStream(raw), JSONUtils.MAP_SUPPLIER);
}
origin: apache/metron

 /**
  * Transforms a bean (aka POJO) to a JSONObject.
  */
 public JSONObject toJSONObject(Object o) throws JsonProcessingException, ParseException {
  return (JSONObject) _parser.get().parse(toJSON(o, false));
 }
}
origin: apache/metron

/**
 * Loads any variables defined in an external file.
 * @param commandLine The command line arguments.
 * @param executor The stellar executor.
 * @throws IOException
 */
private static void loadVariables(
    CommandLine commandLine,
    StellarShellExecutor executor) throws IOException {
 if(commandLine.hasOption("v")) {
  // load variables defined in a file
  String variablePath = commandLine.getOptionValue("v");
  Map<String, Object> variables = JSONUtils.INSTANCE.load(
      new File(variablePath),
      JSONUtils.MAP_SUPPLIER);
  // for each variable...
  for(Map.Entry<String, Object> kv : variables.entrySet()) {
   String variable = kv.getKey();
   Object value = kv.getValue();
   // define the variable - no expression available
   executor.assign(variable, value, Optional.empty());
  }
 }
}
origin: apache/metron

public static void writeConfigToZookeeper(String name, Map<String, Object> config, String zookeeperUrl) throws Exception {
 writeConfigToZookeeper(name, JSONUtils.INSTANCE.toJSON(config), zookeeperUrl);
}
origin: apache/metron

 @Override
 public Object apply(List<Object> strings) {
  if (strings == null || strings.size() == 0) {
   throw new IllegalArgumentException("[TO_JSON_OBJECT] incorrect arguments. Usage: TO_JSON_OBJECT <String>");
  }
  String var = (strings.get(0) == null) ? null : (String) strings.get(0);
  if (var == null) {
   return null;
  } else if (var.length() == 0) {
   return var;
  } else {
   if (!(strings.get(0) instanceof String)) {
    throw new ParseException("Valid JSON string not supplied");
   }
   // Return JSON Object
   try {
    return JSONUtils.INSTANCE.load((String) strings.get(0), Object.class);
   } catch (JsonProcessingException ex) {
    throw new ParseException("Valid JSON string not supplied", ex);
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  return new ParseException("Unable to parse JSON string");
 }
}
origin: apache/metron

public static void writeGlobalConfigToZookeeper(Map<String, Object> globalConfig, CuratorFramework client) throws Exception {
 writeGlobalConfigToZookeeper(JSONUtils.INSTANCE.toJSON(globalConfig), client);
}
origin: apache/metron

/**
 * Executes a given expression on a message.
 *
 * @param expr The filter expression to execute.
 * @param message The message that the expression is executed on.
 * @return Returns true, only if the expression returns true.  If the expression
 * returns false or fails to execute, false is returned.
 */
public boolean isSatisfied(LambdaExpression expr, String message) {
 boolean result = false;
 Map<String, Object> messageAsMap;
 try {
  // transform the message to a map of fields
  messageAsMap = JSONUtils.INSTANCE.load(message, JSONUtils.MAP_SUPPLIER);
  // apply the filter expression
  Object out = expr.apply(Collections.singletonList(messageAsMap));
  if(out instanceof Boolean) {
   result = (Boolean) out;
  } else {
   LOG.error("Expected boolean from filter expression, got {}", ClassUtils.getShortClassName(out, "null"));
  }
 } catch(IOException e) {
  LOG.error("Unable to parse message", e);
 }
 return result;
}
origin: apache/metron

@GET
@Path("/apply")
@Produces("application/json")
public Response apply(@QueryParam("host") String host ) throws JsonProcessingException {
 Boolean b = isMalicious.get(host);
 boolean isMalicious = b != null && b;
 Map<String, Boolean> ret = new HashMap<String, Boolean>();
 ret.put("is_malicious", isMalicious );
 String resp = JSONUtils.INSTANCE.toJSON(ret, true);
 return Response.ok(resp, MediaType.APPLICATION_JSON_TYPE).build();
}
origin: apache/metron

 @Override
 public Object apply(List<Object> strings) {
  if (strings == null || strings.size() == 0) {
   throw new IllegalArgumentException("[TO_JSON_MAP] incorrect arguments. Usage: TO_JSON_MAP <JSON String>");
  }
  String var = (strings.get(0) == null) ? null : (String) strings.get(0);
  if (var == null) {
   return null;
  } else if (var.length() == 0) {
   return var;
  } else {
   if (!(strings.get(0) instanceof String)) {
    throw new ParseException("Valid JSON string not supplied");
   }
   // Return parsed JSON Object as a HashMap
   String in = (String)strings.get(0);
   try {
    return (Map)JSONUtils.INSTANCE.load(in, JSONUtils.MAP_SUPPLIER);
   } catch (JsonProcessingException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string", in), ex);
   } catch (IOException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string", in), ex);
   }
   catch (ClassCastException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string, expected a map", in), ex);
   }
  }
 }
}
origin: apache/metron

 @Override
 public Object apply(List<Object> strings) {
  if (strings == null || strings.size() == 0) {
   throw new IllegalArgumentException("[TO_JSON_LIST] incorrect arguments. Usage: TO_JSON_LIST <JSON String>");
  }
  String var = (strings.get(0) == null) ? null : (String) strings.get(0);
  if (var == null) {
   return null;
  } else if (var.length() == 0) {
   return var;
  } else {
   if (!(strings.get(0) instanceof String)) {
    throw new ParseException("Valid JSON string not supplied");
   }
   // Return parsed JSON Object as a List
   String in = (String)strings.get(0);
   try {
    return (List) JSONUtils.INSTANCE.load(in, JSONUtils.LIST_SUPPLIER);
   } catch (JsonProcessingException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string", in), ex);
   } catch (IOException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string", in), ex);
   }
   catch (ClassCastException ex) {
    throw new ParseException(String.format("%s is not a valid JSON string, expected a list", in), ex);
   }
  }
 }
}
origin: apache/metron

ret = JSONUtils.INSTANCE.load(results, JSONUtils.MAP_SUPPLIER);
resultCache.put(cacheKey, ret);
return ret;
origin: apache/metron

return JSONUtils.INSTANCE.load(json, JSONUtils.MAP_SUPPLIER);
origin: apache/metron

Map<String, Object> variables = new HashMap<>();
if (variablesFile.isPresent()) {
 variables = JSONUtils.INSTANCE.load(new FileInputStream(variablesFile.get()), JSONUtils.MAP_SUPPLIER);
origin: apache/metron

@Test
public void loads_file_with_typeref() throws Exception {
 Map<String, Object> expected = new HashMap<String, Object>() {{
  put("a", "hello");
  put("b", "world");
 }};
 Map<String, Object> actual = JSONUtils.INSTANCE.load(configFile, JSONUtils.MAP_SUPPLIER);
 Assert.assertThat("config not equal", actual, equalTo(expected));
}
origin: apache/metron

@Test
@SuppressWarnings("unchecked")
public void loads_file_with_map_class() throws Exception {
 Map<String, Object> expected = new HashMap<String, Object>() {{
  put("a", "hello");
  put("b", "world");
 }};
 Map<String, Object> actual = JSONUtils.INSTANCE.load(configFile, Map.class);
 Assert.assertThat("config not equal", actual, equalTo(expected));
}
origin: apache/metron

@Test
public void loads_file_with_custom_class() throws Exception {
 TestConfig expected = new TestConfig().setA("hello").setB("world");
 TestConfig actual = JSONUtils.INSTANCE.load(configFile, TestConfig.class);
 Assert.assertThat("a not equal", actual.getA(), equalTo(expected.getA()));
 Assert.assertThat("b not equal", actual.getB(), equalTo(expected.getB()));
}
org.apache.metron.stellar.common.utilsJSONUtils

Most used methods

  • load
  • toJSON

Popular in Java

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getApplicationContext (Context)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JComboBox (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now