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

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

Best Java code snippets using org.apache.metron.stellar.common.utils.JSONUtils.load (Showing top 12 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

/**
 * 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

 @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

/**
 * 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

 @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
@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_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
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.utilsJSONUtilsload

Popular methods of JSONUtils

  • toJSON

Popular in Java

  • Making http post requests using okhttp
  • getResourceAsStream (ClassLoader)
  • getSupportFragmentManager (FragmentActivity)
  • addToBackStack (FragmentTransaction)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JButton (javax.swing)
  • Github Copilot 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