Search code examples
javaxmlnetbeansjax-ws

Want to show certain fields/elements in one operation but not in other


I am making a web service in NetBeans in Java. I have a class Game with the following fields:

private String name;
private double price;
private String category;
private double rating;
private String releaseDate;
private Requirements requirements;
private String description;

The service will have two operations - getGameList and getGameDetails. The problem I am having is that I want to show all the above fields/elements in the getGameDetails response but I wish to show only a selection of the fields/elements (namely name, price and category) in the getGameList operation. I thought one way would be to make two different Game classes for a list search and detail search but I am just asking here to make sure there isn't some obscure method that would let me use the same Game class for both operations.


Solution

  • What do you mean by

    show all the above fields/elements in the getGameDetails

    Do you mean print/show them or return them?

    It seems this class is kinda POJO and entity guy, so usually entity classes are used for holding and representing an object, you may have another class such as GameView which shows the required data of the Game entity class.

    I think having getter method for all the fields is a good approach, then you will be able to get any field you like using getXxx() methods and show them in a form, page or anything...

    Another dirty way is about return the data you like as a generic array(since they are not same type), such as this

    public Object[] getGameList(){return new Object[]{name,price,category};}