@Test public void testToJsonStringWithFilter_01() { User user = new User(); user.setName("xluo"); user.setPassword("xluo"); List<String> books = new ArrayList<String>(); books.add("head of java"); user.setBooks(books); Map<String, Object> friends = new HashMap<String, Object>(); List<User> goodFriends = new ArrayList<User>(); goodFriends.add(new User()); List<User> badFriends = new ArrayList<User>(); badFriends.add(new User()); friends.put("good", goodFriends); friends.put("bad", badFriends); user.setFriends(friends); Map<Class<?>, Set<String>> filter = new HashMap<Class<?>, Set<String>>(); Set<String> set = new HashSet<String>(); set.add("password"); filter.put(User.class, set); System.out.println(FJSONUtil.toJsonString(user, filter)); }
@Test public void testParseObject() { User user = new User(); user.setName("xluo"); user.setPassword("123"); List<String> books = new ArrayList<String>(); books.add("head of java"); books.add("hadoop"); user.setBooks(books); User u = FJSONUtil.parseObject(FJSONUtil.toJsonString(user), User.class); System.out.println(u); }
@Test public void testToJsonString() { User user = new User(); user.setName("xluo"); user.setPassword("xluo"); List<String> books = new ArrayList<String>(); books.add("head of java"); user.setBooks(books); Map<String, Object> friends = new HashMap<String, Object>(); List<User> goodFriends = new ArrayList<User>(); goodFriends.add(new User()); List<User> badFriends = new ArrayList<User>(); badFriends.add(new User()); friends.put("good", goodFriends); friends.put("bad", badFriends); user.setFriends(friends); System.out.println(FJSONUtil.toJsonString(user)); System.out.println(FJSONUtil.toJsonString(user, true)); }