Java Code Examples for net.sf.json.JsonConfig#setJsonPropertyFilter()
The following examples show how to use
net.sf.json.JsonConfig#setJsonPropertyFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackManageAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
public String getBackInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); BackInfo backInfo = new BackInfo(); backInfo.setBorrowId(borrowId); BackInfo newBackInfo = backService.getBackInfoById(backInfo); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBackInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 2
Source File: ZabbixClient.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
protected JsonConfig createDefaultConfig() { JsonConfig config = new JsonConfig(); PropertyNameProcessorMatcher matcher = new PropertyNameProcessorMatcher() { @Override @SuppressWarnings("rawtypes") public Object getMatch(Class target, Set set) { Object key = DEFAULT.getMatch(target, set); if (key == null) { key = Object.class; } return key; } }; config.setJavaPropertyNameProcessorMatcher(matcher); config.setJsonPropertyNameProcessorMatcher(matcher); config.registerJavaPropertyNameProcessor(Object.class, new JavaPropertyNameProcessor()); config.registerJsonPropertyNameProcessor(Object.class, new JsonPropertyNameProcessor()); config.setJsonPropertyFilter(new NullPropertyFilter()); return config; }
Example 3
Source File: QuestionManageAction.java From OnLineTest with Apache License 2.0 | 6 votes |
public String getJudge(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Judge judge = new Judge(); judge.setJudgeId(judgeId); Judge newJudge = questionService.getJudgeById(judge); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newJudge,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 4
Source File: QuestionManageAction.java From OnLineTest with Apache License 2.0 | 6 votes |
public String getChoice(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Choice choice = new Choice(); choice.setChoiceId(choiceId); Choice newChoice = questionService.getChoiceById(choice); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newChoice,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 5
Source File: CourseManageAction.java From OnLineTest with Apache License 2.0 | 6 votes |
public String getAllCourses(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); List<Course> allCourses = courseService.getAllCourses(); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("subjects")){//过滤掉集合 return true; }else{ return false; } } }); String json = JSONArray.fromObject(allCourses,jsonConfig).toString();//List------->JSONArray try { response.getWriter().print(json); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 6
Source File: SubjectManageAction.java From OnLineTest with Apache License 2.0 | 6 votes |
public String getSubject(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Subject subject = new Subject(); subject.setSubjectId(subjectId); Subject newSubject = subjectService.getSubjectById(subject); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("subjects") || name.equals("choices") || name.equals("judges")){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newSubject,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 7
Source File: BorrowAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
public String getBackInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); BackInfo backInfo = new BackInfo(); backInfo.setBorrowId(borrowId); BackInfo newBackInfo = backService.getBackInfoById(backInfo); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBackInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 8
Source File: AuthorizationAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
public String getAuthorization(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Authorization authorization = new Authorization(); authorization.setAid(id); Authorization newAuthorization = authorizationService.getAuthorizationByaid(authorization); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Admin || name.equals("admin")){//过滤掉Authorization中的admin return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newAuthorization,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 9
Source File: ForfeitAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
public String getForfeitInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); ForfeitInfo forfeitInfo = new ForfeitInfo(); forfeitInfo.setBorrowId(borrowId); ForfeitInfo newForfeitInfo = forfeitService.getForfeitInfoById(forfeitInfo); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newForfeitInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 10
Source File: ForfeitManageAction.java From LibrarySystem with Apache License 2.0 | 6 votes |
public String getForfeitInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); ForfeitInfo forfeitInfo = new ForfeitInfo(); forfeitInfo.setBorrowId(borrowId); ForfeitInfo newForfeitInfo = forfeitService.getForfeitInfoById(forfeitInfo); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newForfeitInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 11
Source File: AdminManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定的普通管理员 * Ajax请求该方法 * 向浏览器返回该管理员的json对象 * @return */ public String getAdmin(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Admin admin = new Admin(); admin.setAid(id); Admin newAdmin = adminService.getAdminById(admin); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(name.equals("admin")){//过滤掉Authorization中的admin return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newAdmin,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 12
Source File: BorrowManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 根据借阅id查询该借阅信息 * @return */ public String getBorrowInfoById(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); BorrowInfo info = new BorrowInfo(); info.setBorrowId(borrowId); BorrowInfo newInfo = borrowService.getBorrowInfoById(info); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newInfo,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 13
Source File: BookAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定图书编号的图书信息 * ajax请求该方法 * 返回该图书信息的json对象 * @return */ public String getBook(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Book book = new Book(); book.setBookId(bookId); Book newBook = bookService.getBookById(book);//得到图书 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 14
Source File: TestBookType.java From LibrarySystem with Apache License 2.0 | 5 votes |
@Test public void testFindBookType(){ SessionFactory sessionFactory = (SessionFactory)context.getBean("sessionFactory"); Session session = sessionFactory.openSession(); String hql= "from BookType"; List createQuery = session.createQuery(hql).list(); BookType bookType = (BookType) createQuery.get(0); System.out.println(bookType); // Set<Book> books = bookType.getBooks(); // System.out.println(books.size()); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("books")){ return true; }else{ return false; } } }); String json = JSONArray.fromObject(createQuery,jsonConfig).toString();//List------->JSONArray System.out.println(json); }
Example 15
Source File: ReaderManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定的读者 * @return */ public String getReader(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Reader reader = new Reader(); reader.setReaderId(readerId); Reader newReader = readerService.getReaderById(reader); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("borrowInfos") || obj instanceof Authorization || name.equals("authorization") ){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newReader,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 16
Source File: BookTypeManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到图书类型 * ajax请求该方法 * 返回图书类型集合的json对象 * @return */ public String getBookType(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); BookType bookType = new BookType(); bookType.setTypeId(id); BookType newType = bookTypeService.getBookTypeById(bookType); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Set||name.equals("books")){//过滤掉集合 return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newType,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }
Example 17
Source File: MenuManagerController.java From jeewx with Apache License 2.0 | 5 votes |
@RequestMapping(params = "getSubMenu") public void getSubMenu(HttpServletRequest request, HttpServletResponse response) { String accountid = ResourceUtil.getWeiXinAccountId(); String msgType = request.getParameter("msgType"); String resMsg = ""; JsonConfig config = new JsonConfig(); config.setJsonPropertyFilter(new PropertyFilter(){ public boolean apply(Object source, String name, Object value) { if(name.equals("menuList")) { //要过滤的areas ,Map对象中的 return true; } else { return false; } } }); List<MenuEntity> textList = this.weixinMenuService .findByQueryString("from MenuEntity t where t.accountId = '" + accountid+ "'"); JSONArray json = JSONArray.fromObject(textList,config); resMsg = json.toString(); try { response.setCharacterEncoding("utf-8"); PrintWriter writer = response.getWriter(); writer.write(resMsg); writer.flush(); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example 18
Source File: JsonConfigs.java From zxl with Apache License 2.0 | 5 votes |
public static JsonConfig propertiesFilter(final String... names) { final List<String> nameList = Arrays.asList(names); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { @Override public boolean apply(Object source, String name, Object value) { if (nameList.contains(name)) { return true; } return false; } }); return jsonConfig; }
Example 19
Source File: JsonConfigs.java From zxl with Apache License 2.0 | 5 votes |
public static JsonConfig propertiesFilter(final Map<Class<?>, List<String>> clazzNamesMap) { JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { @Override public boolean apply(Object source, String name, Object value) { if (clazzNamesMap.containsKey(source.getClass()) && clazzNamesMap.get(source.getClass()).contains(name)) { return true; } return false; } }); return jsonConfig; }
Example 20
Source File: BookManageAction.java From LibrarySystem with Apache License 2.0 | 5 votes |
/** * 得到指定图书编号的图书信息 * ajax请求该方法 * 返回该图书信息的json对象 * @return */ public String getBook(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/json;charset=utf-8"); Book book = new Book(); book.setBookId(bookId); Book newBook = bookService.getBookById(book);//得到图书 JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new PropertyFilter() { public boolean apply(Object obj, String name, Object value) { if(obj instanceof Authorization||name.equals("authorization")){ return true; }else{ return false; } } }); JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig); try { response.getWriter().print(jsonObject); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } return null; }