#1018 - HAL Forms properties customizable via annotations on representation model classes.
We now consider additional Jackson and JSR-303 annotations on representation models to enrich the HAL Forms template properties with additional information: - @NotNull on a property flips its `required` flag to `true`. - The "regexp" attribute of @Pattern on a property is forwarded into the "regex" field. - @JsonProperty(Access.READ_ONLY) on a property is translated into the "readOnly" flag. The default for the "required" flag have been changed to false even for PUT and POST as whether they're required or not is completely determined by the model, not the HTTP method. All of this is backed by significant refactoring in the way that Affordance instances are build internally. The new API is centered around the Affordances type in the mediatype package. The methods on Link to create the Affordance` from its details have been removed and replaced by builder style APIs on Affordance. AffordanceModelFactory has been moved to the mediatype as well. PropertyUtils has been significantly revamped to expose a PayloadMetadata/PropertyMetadata model to abstract the individual traits of a property. This allows to optionally plug in the support for JSR-303 annotations. AffordanceModelFactory has been refactored to rather work with those instead of ResolvableType.
This commit is contained in:
@@ -31,8 +31,6 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -211,60 +209,6 @@ public class Link implements Serializable {
|
||||
return withAffordances(newAffordances);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method when chaining an existing {@link Link}.
|
||||
*
|
||||
* @param name
|
||||
* @param httpMethod
|
||||
* @param inputType
|
||||
* @param queryMethodParameters
|
||||
* @param outputType
|
||||
* @return
|
||||
*/
|
||||
public Link andAffordance(String name, HttpMethod httpMethod, ResolvableType inputType,
|
||||
List<QueryParameter> queryMethodParameters, ResolvableType outputType) {
|
||||
return andAffordance(new Affordance(name, this, httpMethod, inputType, queryMethodParameters, outputType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method when chaining an existing {@link Link}. Defaults the name of the affordance to verb + classname,
|
||||
* e.g. {@literal <httpMethod=HttpMethod.PUT, inputType=Employee>} produces {@literal <name=putEmployee>}.
|
||||
*
|
||||
* @param httpMethod
|
||||
* @param inputType
|
||||
* @param queryMethodParameters
|
||||
* @param outputType
|
||||
* @return
|
||||
*/
|
||||
public Link andAffordance(HttpMethod httpMethod, ResolvableType inputType, List<QueryParameter> queryMethodParameters,
|
||||
ResolvableType outputType) {
|
||||
|
||||
String name = httpMethod.toString().toLowerCase();
|
||||
|
||||
Class<?> resolvedInputType = inputType.resolve();
|
||||
if (resolvedInputType != null) {
|
||||
name += resolvedInputType.getSimpleName();
|
||||
}
|
||||
|
||||
return andAffordance(name, httpMethod, inputType, queryMethodParameters, outputType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method when chaining an existing {@link Link}. Defaults the name of the affordance to verb + classname,
|
||||
* e.g. {@literal <httpMethod=HttpMethod.PUT, inputType=Employee>} produces {@literal <name=putEmployee>}.
|
||||
*
|
||||
* @param httpMethod
|
||||
* @param inputType
|
||||
* @param queryMethodParameters
|
||||
* @param outputType
|
||||
* @return
|
||||
*/
|
||||
public Link andAffordance(HttpMethod httpMethod, Class<?> inputType, List<QueryParameter> queryMethodParameters,
|
||||
Class<?> outputType) {
|
||||
return andAffordance(httpMethod, ResolvableType.forClass(inputType), queryMethodParameters,
|
||||
ResolvableType.forClass(outputType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {@link Link} with additional {@link Affordance}s.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user