Assuming the following class:
public class Foo {
String a, b, c, d;
// The rest of the class...
}
And a REST API controller using Springboot:
@GetMapping("/foo")
public Foo myFuntion() {
return new Foo(...);
}
Requesting /foo return this JSON:
{
"a": "...",
"b": "...",
"c": "...",
"d": "..."
}
However, I would like to return only some attributes of the Foo class, for example, only attributes a and b.
How could I do that without creating a new class?
@JsonIgnoreon it. If you need to return different sets of properties in different places useDTOs.