spring-hateoas icon indicating copy to clipboard operation
spring-hateoas copied to clipboard

HAL-FORMS properties marked readOnly when @JsonCreator is available.

Open marcuslange opened this issue 6 years ago • 4 comments
trafficstars

In cases where command style objects are used for PUT and POST we use immutable object with a @JsonCreator annotation. I think this is something that should be available in the affordances rendering vs just marking them readOnly.

marcuslange avatar Sep 16 '19 19:09 marcuslange

Can you paste a simple example? I'd love to accommodate your needs.

gregturn avatar Sep 16 '19 21:09 gregturn

@Getter
public class CreateUser {
    @JsonProperty("first_name")
    private final String firstName;
    @JsonProperty("last_name")
    private final String lastName;
    @JsonProperty("email")
    private final String email;
    @JsonProperty("home_phone")
    private final String homePhone;
    @JsonProperty("cell_phone")
    private final String cellPhone;

   @JsonCreator
    public CreateUser(@JsonProperty("first_name") String firstName,
                      @JsonProperty("last_name") String lastName,
                      @JsonProperty("email") String email,
                      @JsonProperty("home_phone") @Nullable  String homePhone,
                      @JsonProperty("cell_phone") @Nullable String cellPhone) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.homePhone = homePhone;
        this.cellPhone = cellPhone;
    }
}

I would expect for this you have HAL-FORM that is not marked readOnly and required false on the @Nullable fields.

marcuslange avatar Sep 17 '19 00:09 marcuslange

That’s a tricky one as we‘d need access to Jackson’s mapping information, which properties it considers creators etc. and currently out property metamodel is entirely driven from a static context that doesn’t know anything about Jackson.

I’ll see whether we can abstract that away as it looks like the property inspection is usually triggered from within a context in which we have access to an AnnotationIntrospector, so that we could wrap that into an implementation of an interface that all downstream components use to decide whether a property is a creator property.

odrotbohm avatar Sep 20 '19 16:09 odrotbohm

@odrotbohm , I think java Record could be at least excluded from this behaviour by default. What do you think?

reda-alaoui avatar Jul 10 '23 16:07 reda-alaoui