Exemplo n.º 1
0
  @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));
  }
Exemplo n.º 2
0
  @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);
  }
Exemplo n.º 3
0
  public static List<UserBookDto> changeToDto(User user, List<Book> books) {

    List<UserBookDto> dto = new ArrayList<UserBookDto>();
    for (Book book : books) {
      UserBookDto d = new UserBookDto();
      d.setUsername(user.getUsername());
      d.setIsreturn("N");
      d.setBookname(book.getBookname());
      dto.add(d);
    }
    return dto;
  }
Exemplo n.º 4
0
  @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));
  }