public static String toJSON(final Object obj) { return toJSON(obj, false); }
public static Object parseJSONFromStringQuiet(final String json) { try { return parseJSONFromString(json); } catch (final IOException e) { e.printStackTrace(); return null; } }
break; default: if (isCharSpecialUnicode(ch)) { buffer.append("\\u"); final String hexCode = Integer.toHexString(ch);
@Test public void writePropsNoJarDependencyTest2() throws IOException { final Map<String, String> test = new HashMap<>(); test.put("\"myTest\n\b", "myValue\t\\"); final StringWriter writer = new StringWriter(); JSONUtils.writePropsNoJarDependency(test, writer); final String jsonStr = writer.toString(); System.out.println(writer.toString()); final Map<String, String> result = (Map<String, String>) JSONUtils.parseJSONFromString(jsonStr); checkInAndOut(test, result); }
@Test public void testExecutorFlowJson() throws Exception { final Flow flow = this.project.getFlow("jobe"); Assert.assertNotNull(flow); final ExecutableFlow exFlow = new ExecutableFlow(this.project, flow); final Object obj = exFlow.toObject(); final String exFlowJSON = JSONUtils.toJSON(obj); final Map<String, Object> flowObjMap = (Map<String, Object>) JSONUtils.parseJSONFromString(exFlowJSON); final ExecutableFlow parsedExFlow = ExecutableFlow.createExecutableFlowFromObject(flowObjMap); testEquals(exFlow, parsedExFlow); }
temp.deleteOnExit(); final Object obj = cond.toJson(); JSONUtils.toJSON(obj, temp); final Condition cond2 = Condition.fromJson(JSONUtils.parseJSONFromFile(temp));
public static Object parseJSONFromString(final String json) throws IOException { final ObjectMapper mapper = new ObjectMapper(); final JsonFactory factory = new JsonFactory(); final JsonParser parser = factory.createJsonParser(json); final JsonNode node = mapper.readTree(parser); return toObjectFromJSONNode(node); }
@SuppressWarnings("unchecked") private void handleAjaxUpdateRequest(HttpServletRequest req, Map<String, Object> respMap) throws ServletException, IOException { ArrayList<Object> updateTimesList = (ArrayList<Object>)JSONUtils.parseJSONFromString(getParam(req, UPDATE_TIME_LIST_PARAM)); ArrayList<Object> execIDList = (ArrayList<Object>)JSONUtils.parseJSONFromString(getParam(req, EXEC_ID_LIST_PARAM)); ArrayList<Object> updateList = new ArrayList<Object>(); for (int i = 0; i < execIDList.size(); ++i) { long updateTime = JSONUtils.getLongFromObject(updateTimesList.get(i)); int execId = (Integer)execIDList.get(i); ExecutableFlowBase flow = flowRunnerManager.getExecutableFlow(execId); if (flow == null) { Map<String, Object> errorResponse = new HashMap<String,Object>(); errorResponse.put(RESPONSE_ERROR, "Flow does not exist"); errorResponse.put(UPDATE_MAP_EXEC_ID, execId); updateList.add(errorResponse); continue; } if (flow.getUpdateTime() > updateTime) { updateList.add(flow.toUpdateObject(updateTime)); } } respMap.put(RESPONSE_UPDATED_FLOWS, updateList); }
public static void writePropsNoJarDependency(final Map<String, String> properties, final Writer writer) throws IOException { writer.write("{\n"); int size = properties.size(); for (final Map.Entry<String, String> entry : properties.entrySet()) { // tab the space writer.write('\t'); // Write key writer.write(quoteAndClean(entry.getKey())); writer.write(':'); writer.write(quoteAndClean(entry.getValue())); size -= 1; // Add comma only if it's not the last one if (size > 0) { writer.write(','); } writer.write('\n'); } writer.write("}"); }
if (!disabled.isEmpty()) { final List<Object> disabledList = (List<Object>) JSONUtils.parseJSONFromStringQuiet(disabled); execOptions.setDisabledJobs(disabledList);
public static ExecutableFlow createTestExecutableFlow(final String projectName, final String flowName) throws IOException { final File jsonFlowFile = ExecutionsTestUtil.getFlowFile(projectName, flowName + ".flow"); final HashMap<String, Object> flowObj = (HashMap<String, Object>) JSONUtils.parseJSONFromFile(jsonFlowFile); final Flow flow = Flow.flowFromObject(flowObj); final Project project = new Project(1, "flow"); final HashMap<String, Flow> flowMap = new HashMap<>(); flowMap.put(flow.getId(), flow); project.setFlows(flowMap); final ExecutableFlow execFlow = new ExecutableFlow(project, flow); return execFlow; }
@Test public void testToAndFromObject() throws Exception { final Project project = new Project(1, "tesTing"); project.setCreateTimestamp(1L); project.setLastModifiedTimestamp(2L); project.setDescription("I am a test"); project.setUserPermission("user1", new Permission(new Type[]{Type.ADMIN, Type.EXECUTE})); final Object obj = project.toObject(); final String json = JSONUtils.toJSON(obj); final Object jsonObj = JSONUtils.parseJSONFromString(json); final Project parsedProject = Project.projectFromObject(jsonObj); assertTrue(project.equals(parsedProject)); }
temp.deleteOnExit(); final Object obj = t.toJson(); JSONUtils.toJSON(obj, temp); final Trigger t2 = Trigger.fromJson(JSONUtils.parseJSONFromFile(temp));
public static Object parseJSONFromFile(final File file) throws IOException { final ObjectMapper mapper = new ObjectMapper(); final JsonFactory factory = new JsonFactory(); final JsonParser parser = factory.createJsonParser(file); final JsonNode node = mapper.readTree(parser); return toObjectFromJSONNode(node); }
@Test public void writePropsNoJarDependencyTest1() throws IOException { final Map<String, String> test = new HashMap<>(); test.put("\"myTest\n\b", "myValue\t\\"); test.put("normalKey", "Other key"); final StringWriter writer = new StringWriter(); JSONUtils.writePropsNoJarDependency(test, writer); final String jsonStr = writer.toString(); System.out.println(writer.toString()); final Map<String, String> result = (Map<String, String>) JSONUtils.parseJSONFromString(jsonStr); checkInAndOut(test, result); }
@SuppressWarnings("unchecked") private void handleAjaxUpdateRequest(HttpServletRequest req, HashMap<String, Object> respMap) { try { ArrayList<Object> updateTimesList = (ArrayList<Object>)JSONUtils.parseJSONFromString(getParam(req, ExecutorManagerAdapter.INFO_UPDATE_TIME_LIST)); ArrayList<Object> execIDList = (ArrayList<Object>)JSONUtils.parseJSONFromString(getParam(req, ExecutorManagerAdapter.INFO_EXEC_ID_LIST)); long updateTime = JSONUtils.getLongFromObject(updateTimesList.get(i)); int execId = (Integer)execIDList.get(i);
public static void writePropsNoJarDependency(Map<String, String> properties, Writer writer) throws IOException { writer.write("{\n"); int size = properties.size(); for (Map.Entry<String, String> entry: properties.entrySet()) { // tab the space writer.write('\t'); // Write key writer.write(quoteAndClean(entry.getKey())); writer.write(':'); writer.write(quoteAndClean(entry.getValue())); size -= 1; // Add comma only if it's not the last one if (size > 0) { writer.write(','); } writer.write('\n'); } writer.write("}"); }
if (!disabled.isEmpty()) { final List<Object> disabledList = (List<Object>) JSONUtils.parseJSONFromStringQuiet(disabled); execOptions.setDisabledJobs(disabledList);
private static Map<String, Object> loadCache(int scheduleId) { Object lock = getLock(scheduleId); try { synchronized (lock) { File cache = getCacheFile(scheduleId); if (cache.exists() && cache.isFile()) { Object dataObj = JSONUtils.parseJSONFromFile(cache); if (dataObj instanceof Map<?, ?>) { @SuppressWarnings("unchecked") Map<String, Object> data = (Map<String, Object>) dataObj; return data; } } } } catch (Exception e) { e.printStackTrace(); } unLock(scheduleId); return null; }
public static void toJSON(final Object obj, final File file) throws IOException { toJSON(obj, file, false); }