Skip to content

HAL Forms properties should consider Jackson constructors #1274

Open
@reda-alaoui

Description

@reda-alaoui

Hello,

Let's consider the following controller:

@RequestMapping("/foos")
public class FooController {

  @GetMapping
  public ResponseEntity<?> list() {
    return ResponseEntity.ok(
          new CollectionModel<>(
              Collections.emptyList(),
              selfLink.andAffordance(
                  afford(
                      methodOn(FooController.class).create(null)))));
  }

  @PostMapping
  public ResponseEntity<?> create(@RequestBody CreateCommand command) {
    //...
  }

  private static class CreateCommand {
    private final String name;
    
    @JsonCreator
    CreateCommand(@JsonProperty("name") String name){
      this.name = name;
    }
  }
}

FooController#list produces:

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/foos"
    }
  },
  "_templates": {
    "default": {
      "method": "post",
      "properties": []
    }
  }
}

As you can see, property name is missing.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions