Naresh Gounder
Naresh Gounder

Reputation: 133

How to reduce no. of json fields in response of spring restful services

this is the code:

public class RestApi_Controller {


@Autowired
public AirportRepo Airport_Repository;

@RequestMapping(value="/airport/{indexid}", method=RequestMethod.GET)
public List<Master_Airport> getAirportIndexid(@PathVariable int indexid)
{

    return Airport_Repository.findByIndexid(indexid);
  }
 }

Can any one help me out using json filter??

Airport Collection contains:

private int indexid;
private String airportcode;
private String airportname;
private String code;

Upvotes: 0

Views: 339

Answers (1)

Sampada
Sampada

Reputation: 2991

You can use Jackson Annotations to achieve this.

Add Jackson dependency or its jars to your code and annotate the fields like this:

@JsonIgnore
private int indexid;
private String airportcode;
@JsonIgnore
private String airportname;
private String code;

This will ignore indexid and airportname in the response.

More details can be found here

Upvotes: 1

Related Questions