net.sf.json.util.PropertyFilter Java Examples

The following examples show how to use net.sf.json.util.PropertyFilter. 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: ItemClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * アイテム情報を取得します。<br/>
 * アイテム情報が存在しない場合、空のリストを返します。
 *
 * @param param {@link ItemGetParam}
 * @return 取得したアイテム情報のリスト
 */
@SuppressWarnings("unchecked")
public List<Item> get(ItemGetParam param) {
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONArray result = (JSONArray) accessor.execute("item.get", params);

    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(Item.class);
    config.setJavaPropertyFilter(new PropertyFilter() {
        @Override
        public boolean apply(Object source, String name, Object value) {
            if ("hosts".equals(name)) {
                return true;
            }
            return false;
        }
    });

    return (List<Item>) JSONArray.toCollection(result, config);
}
 
Example #2
Source File: TriggerClient.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
/**
 * トリガー情報を取得します。<br/>
 * トリガー情報が存在しない場合、空のリストを返します。
 *
 * @param param {@link TriggerGetParam}
 * @return 取得したトリガー情報のリスト
 */
@SuppressWarnings("unchecked")
public List<Trigger> get(TriggerGetParam param) {
    JSONObject params = JSONObject.fromObject(param, defaultConfig);
    JSONArray result = (JSONArray) accessor.execute("trigger.get", params);

    JsonConfig config = defaultConfig.copy();
    config.setCollectionType(List.class);
    config.setRootClass(Trigger.class);
    config.setJavaPropertyFilter(new PropertyFilter() {
        @Override
        public boolean apply(Object source, String name, Object value) {
            if ("hosts".equals(name)) {
                return true;
            }
            return false;
        }
    });

    return (List<Trigger>) JSONArray.toCollection(result, config);
}
 
Example #3
Source File: ForfeitManageAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: ForfeitAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: AuthorizationAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: BorrowAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: BackManageAction.java    From LibrarySystem with Apache License 2.0 6 votes vote down vote up
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: SubjectManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: CourseManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: QuestionManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
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 #11
Source File: QuestionManageAction.java    From OnLineTest with Apache License 2.0 6 votes vote down vote up
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 #12
Source File: TestBookType.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: JsonConfigs.java    From zxl with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: JsonConfigs.java    From zxl with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: MenuManagerController.java    From jeewx with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: CustomJsonConfig.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
public CustomJsonConfig(Class clazz,final String[] excludes){
	this.clazz = clazz;
	setRootClass(clazz);
	setJavaPropertyFilter(new PropertyFilter() {
		public boolean apply(Object arg0, String param, Object arg2) {
			for(String exclude:excludes){
				if(param.equals(exclude))return true;
			}
			return false;
		}
	});
}
 
Example #17
Source File: CustomJsonConfig.java    From jeewx-api with Apache License 2.0 5 votes vote down vote up
public CustomJsonConfig(Class clazz,final String exclude){
	this.clazz = clazz;
	setRootClass(clazz);
	setJavaPropertyFilter(new PropertyFilter() {
		public boolean apply(Object arg0, String param, Object arg2) {
			if(param.equals(exclude))return true;
			return false;
		}
	});
}
 
Example #18
Source File: BookAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 得到指定图书编号的图书信息
 * 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 #19
Source File: BorrowManageAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 根据借阅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 #20
Source File: AdminManageAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 得到指定的普通管理员
 * 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 #21
Source File: ReaderManageAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 得到指定的读者
 * @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 #22
Source File: BookTypeManageAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 得到图书类型
 * 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 #23
Source File: BookManageAction.java    From LibrarySystem with Apache License 2.0 5 votes vote down vote up
/**
 * 得到指定图书编号的图书信息
 * 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;
}