JsonStringToMap extends EvalFunc<Map<String, String>> { @Override public Map<String, String> exec(Tuple input) throws IOException { try { if (input == null || input.size() < 1) { throw new IOException("Not enough arguments to " + this.getClass().getName() + ": got " + input.size() + ", expected at least 1"); } if (input.get(0) == null) { counterHelper.incrCounter(getClass().getName(), "NullJsonString", 1L); return null; } String jsonLiteral = (String) input.get(0); return parseStringToMap(jsonLiteral); } catch (ExecException e) { LOG.warn("Error in " + getClass() + " with input " + input, e); throw new IOException(e); } }  @Override Schema outputSchema(Schema input); @Override Map<String, String> exec(Tuple input);  }
@Test public final void testStandard() throws IOException, ExecException { Tuple input = tupleFactory_.newTuple(Arrays.asList("{\"name\": \"value\", \"number\": 2}")); Map<String, String> result = udf_.exec(input); assertTrue("It should return a Map", result instanceof Map<?, ?>); assertEquals("value", result.get("name")); assertEquals("It is expected to return numbers as strings", "2", result.get("number")); }
@Test public final void testNestedJson() throws IOException, ExecException { Tuple input = tupleFactory_.newTuple(Arrays .asList("{\"name\": \"value\", \"nestedJson\": {\"json\": \"ihazit\"}}")); Map<String, String> result = udf_.exec(input); assertTrue("Nested Json should just return as a String", result.get("nestedJson") instanceof String); }