I have Java bean:
public class User {
private int id;
private String name;
private Address address;
private List<String> favoriteBooks;
private List<String> favoriteFilms;
//getters and setter
}
I want convert instance of User class into JSON format, but selecting only three fields: id, name, favoriteBooks. I search some solution like
String[] fieldNames = { "id", "name", "favoriteBooks" };
JsonObject jo = new JsonObject(user, fieldNames);
How can I do it?
EDIT I found the answer here https://stackoverflow.com/a/13792700 with using Jackson library