@Test public void shortArray() throws MapperException { mapper.addHelper(new ShortMapper()); short[] arr = new short[] {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; JSONValue json = helper.toJSON(mapper, arr); Assert.assertThat(json, is(instanceOf(JSONArray.class))); // Object back = helper.toJava(mapper, json, short[].class); Assert.assertArrayEquals(arr, (short[]) back); }
@Test public void charArray() throws MapperException { mapper.addHelper(new CharacterMapper()); char[] arr = new char[] {'a', 'b', 'c'}; JSONValue json = helper.toJSON(mapper, arr); Assert.assertThat(json, is(instanceOf(JSONArray.class))); // Object back = helper.toJava(mapper, json, char[].class); Assert.assertArrayEquals(arr, (char[]) back); }
@Test public void boolArray() throws MapperException { mapper.addHelper(new BooleanMapper()); boolean[] arr = new boolean[] {true, false, false, true, true}; JSONValue json = helper.toJSON(mapper, arr); Assert.assertThat(json, is(instanceOf(JSONArray.class))); // Object back = helper.toJava(mapper, json, boolean[].class); Assert.assertTrue(Arrays.equals(arr, (boolean[]) back)); }
@Test public void doubleArray() throws MapperException { mapper.addHelper(new DoubleMapper()); double[] arr = new double[] {-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; JSONValue json = helper.toJSON(mapper, arr); Assert.assertThat(json, is(instanceOf(JSONArray.class))); // Object back = helper.toJava(mapper, json, double[].class); Assert.assertTrue(Arrays.equals(arr, (double[]) back)); }
@Test public void objArray() throws MapperException { mapper.addHelper(new ObjectMapperFields()); A[] arr = new A[] {new A(), new A(), new A(), new A(), new A()}; JSONValue json = helper.toJSON(mapper, arr); Assert.assertThat(json, is(instanceOf(JSONArray.class))); // Object back = helper.toJava(mapper, json, A[].class); A[] backa = (A[]) back; Assert.assertTrue(backa.length == arr.length); for (int i = 0; i < backa.length; i++) Assert.assertNotNull(backa[i]); }
public static String getComboBoxJsonBySqlFormat(List<Object> list, String column) { String[] columns = column.split(","); List<Map> workMesions = new ArrayList<Map>(); if (dbtype.equalsIgnoreCase("db2")) { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { map.put(columns[j], wm[j]); } workMesions.add(map); } } else { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { map.put(columns[j], wm[j]); } workMesions.add(map); } } // if(isneedall!=""&&isneedall!=null){ // for(int j=0;j<columns.length;j++){ // HashMap map = new HashMap(); // map.put(columns[j],""); // workMesions.add(map); // } // } StringBuilder tempJsonString = new StringBuilder(""); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(workMesions); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); JsonString = tempJsonString.toString(); return JsonString; }
@Override public Map<String, Object> handleController(HttpServletRequest request) throws Exception { Map<String, Object> model = new HashMap<String, Object>(); Long id = Long.parseLong(request.getPathInfo().substring(8)); TestRun testRun = testRunDAO.getRunById(id); if (testRun == null) { throw new UnexistentResource("Test run with id = " + id + " doesn't exist"); } Long projectId = testRun.getProjectId(); Long testId = testRun.getTestId(); Long suiteRunId = testRun.getSuiteRunId(); model.put("testRun", testRun); if (projectId != null && projectId > 0) { model.put("project", projectDAO.getProject(projectId)); } if (testId != null && testId > 0) { model.put("test", testDAO.getTest(testId)); } if (suiteRunId != null && suiteRunId > 0) { model.put("suiteRun", testRunDAO.getSuiteRun(suiteRunId)); } model.put("testRunParameters", testRunDAO.getTestRunParameters(testRun.getId())); if (testRun.getIssueId() != null && testRun.getIssueId() > 0) { model.put("issue", issueDAO.getIssue(testRun.getIssueId())); } XmlReportRender reportRender = new XmlReportRender(); ReportNode reportNode = reportRender.decode(testRun.getReport()); updateReport(reportNode, 0, new IdGenerator()); JSONValue jsonValue = JSONMapper.toJSON(reportNode); String jsonString = jsonValue.render(false); model.put("report", reportNode); model.put("json", jsonString); return model; }
public static String getGridJsonFormat(int sumnum, List<Object> list) { String ddd = ""; if (sumnum == 0) { JsonString = "{totalProperty:0,root:);"; return "{totalProperty:" + sumnum + ",root:[]}"; } else { // StringBuffer tempJsonString =null; StringBuilder tempJsonString = new StringBuilder("{totalProperty:" + sumnum + ",root:"); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(list); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); tempJsonString.append("}"); JsonString = tempJsonString.toString(); } return JsonString; }
public static String getGridJsonBySqlFormat(int sumnum, List<Object> list, String column) { if (sumnum == 0) { // System.out.println("总条数为0 ,没有数据可以格式化..."); return "{totalProperty:" + sumnum + ",root:[]}"; } else { // StringBuffer tempJsonString =null; String[] columns = column.split(","); List<Map> workMesions = new ArrayList<Map>(); if (dbtype.equalsIgnoreCase("db2")) { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { if (wm[j + 1] == null) { wm[j + 1] = ""; } if (wm[j + 1].getClass().isEnum()) { wm[j] = wm[j + 1].toString().trim(); } // System.out.println(wm[j]); map.put(columns[j], wm[j + 1]); } workMesions.add(map); // } // else{ // System.out.println(columns.length); // System.out.println(wm.length); // for(int j=0;j<wm.length;j++){ // System.out.println(wm[j]); // } // System.out.println("字段数量不符合,请核对column参数"); // } } } else { for (Object i : list) { Object[] wm = (Object[]) i; // if(columns.length == wm.length){ HashMap map = new HashMap(); for (int j = 0; j < columns.length; j++) { if (wm[j] == null) { wm[j] = ""; } if (wm[j].getClass().isEnum()) { wm[j] = wm[j].toString().trim(); } // System.out.println(wm[j]); map.put(columns[j], wm[j]); } workMesions.add(map); // } // else{ // System.out.println(columns.length); // System.out.println(wm.length); // for(int j=0;j<wm.length;j++){ // System.out.println(wm[j]); // } // System.out.println("字段数量不符合,请核对column参数"); // } } } StringBuilder tempJsonString = new StringBuilder(" { "); tempJsonString.append("totalProperty:" + sumnum + ",root:"); JSONValue JSONArray; try { JSONArray = JSONMapper.toJSON(workMesions); JsonString = JSONArray.render(true); } catch (MapperException e) { // TODO Auto-generated catch block e.printStackTrace(); } tempJsonString.append(JsonString); tempJsonString.append("}"); JsonString = tempJsonString.toString(); } return JsonString; }
@Test(expected = MapperException.class) public void badInput3() throws MapperException { mapper.addHelper(new IntegerMapper()); helper.toJava(mapper, new JSONArray(), A.class); }
@Test(expected = MapperException.class) public void badInput2() throws MapperException { mapper.addHelper(new IntegerMapper()); helper.toJava(mapper, new JSONString("ai"), int[].class); }
@Test(expected = MapperException.class) public void badInput() throws MapperException { mapper.addHelper(new IntegerMapper()); helper.toJSON(mapper, new A()); }