79224366

Date: 2024-11-25 19:29:28
Score: 0.5
Natty:
Report link

What about a simpler approach:

Let's create a class:

public class FooDto {

@NotNull
private final Foo foo;

public FooDto(Foo foo) {

 this.foo = foo;

}

public String getName() {
 return foo.name();
}

public String getDescription() {
 return foo.getLabel();
}

}

And then in Controller:

@GetMapping
public ResponseEntity<Set<FooDto>> allOfFoo() {
  return ResponseEntity.ok(EnumSet.allOf(Foo.class).stream().map(f -> new FooDto(f)).collect(Collectors.toSet()));
}

Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): What
  • Low reputation (0.5):
Posted by: Aleksander Burzec