Both _links and _embedded are now only rendered if there's actual content to be rendered. The curies link is now always rendered as array as specified.
The LinkDiscoverer interface is now a Plugin<MediaType> to allow selecting a discoverer per media type. We also provide a LinkDiscoverers wrapper around a PluginRegistry for easier injection.
Dropped DefaultLinkDiscoverer as the above mentioned changed prohibits the usage of a discoverer without a media type. Clients that previously used DefaultLinkDiscoverer should switch to JsonPathLinkDiscoverer with a custom JsonPath expression and media type.
@EnableHypermediaSupport now supports multiple HypermediaType values set to be able to set up support for multiple hypermedia formats. Admittedly, the only currently supported type is HAL but we prepare for the addition of other (e.g. Collection/JSON or the like). We changed the infrastructure setup taken care of by @EnableHypermediaSupport to not enrich all ObjectMapper instances with our HAL modules but explicitly register an ObjectMapper with the application context and then registering a custom MappingJackson(2)HttpMessageConverter with the HandlerAdapter instances present in the ApplicationContext. We skip the registration if an already registered MJ2HMC has an ObjectMapper already supporting the Spring HATEOAS mixins.
Removed some compiler warnings.
Introduced CurieProvider interface as well as a DefaultCurieProvider that can be registered as Spring Bean to enable Links being rendered in a curie namespace and an additional curie link exposing the metadata of how to lookup the rel definition.
Deprecated Jackson 1 integration. Added helper class to find out whether a relation type is defined by the IANA.
PageMetadata doesn't reject empty pages anymore if they're used with 1-indexed Pageables. Also tweaked the assertions to only reject negative values for now.
MethodParameters can now get an AnnotationAttribute configured that will be inspected for parameter name lookup. If it's not set or no annotated parameter is found we fall back to the standard behavior of MethodParameter and use a LocalVariableTableParameterNameDiscoverer.
We need to have a different XML element name for PagedResources as it can be used as root element and JAXB cannot tell the difference between Resource and PagedResource otherwise.
ControllerLinkBuilder now correctly uses the X-Fowarded-Host header by inspecting it for a port being set and configuring the discovered one on the ServletUriComponentsBuilder created.
Also added that the first host listed in the header is used.
Removed JsonAutoDetect annotations from PagedResources as the reference to Visibility was causing compile errors in case one of the 2 Jackson variants was not on the classpath (which by design will usually be the case). Generally, the annotations weren't required anymore so that we could remove them.
Upgraded to Spring 3.2.3 to be able to use inlined CGLib directly. We now use Objenesis to create the proxy instances which avoids the need for a default constructor.
The HeaderLinksResponseEntity wraps any HttpEntity containing a ResourceSupport and will transform it to contain the Links the ResourceSupport instance held in the first place in the entities headers now.
This change is to essentially prevent people from subclassing Resource and call the default constructor which wrecks the assumption of content never being null. For custom resources extend ResourceSupport.
Added missing license header in ResourcesMixin.
When embedding values into HAL representations we now correctly expose the collection relation type as exposed by RelProvider.getCollectionResourceRelFor(…). Added EmbeddedHalBuilder to ease building these kinds of nested maps easily and use the commonly shared code between Jackson 1 and 2 implementations.
Introduced representation models for the application/vnd.error media type as specified in [0]. Added default mapping annotations to get it rendered in XML (via JAXB), and JSON (via Jackson 1 and 2).
[0] https://github.com/blongden/vnd.error
The String value handed into the UriTemplate created through mock method invocations now uses a DefaultFormattingConversionService to consider formatting annotations on the controller method parameters.
Added @Relation annotation to be able to define the relations that shall be exposed. The annotation can be used on domain classes or ResourceSupport subtypes to define the relations that shall be used to build links pointing to them.
Introduced RelProvider implementations that use the plain domain class name plus an appended List by default (DefaultRelProvider, fallback) as well as an AnnotationRelProvider that will inspect @Relation on the domain type. Added a DelegatingRelProvider that is based on a Spring Plugin PluginRegistry to allow adding RelProvider implementations transparently. Polished AnnotationRelProvider (added annotation caching) and corrected ControllerRelProvider to lookup relation types from Controller classes. Added BeanDefinition setup to HypermediaSupportBeanDefinitionRegistrar to setup a PluginRegistry of RelProviders and the wrapping DelegatingRelProvider to become the primary auto wiring candidate.
Moved RelProvider registration into Jackson HandlerInstantiator implementations. Made the BeanPostProcessors for Jackson ObjectMapper customization aware of the BeanFactory to lookup the DelegatingRelProvider instance to hand them into the Jackson HandlerInstantiators.
TODOs:
- More tests
- Correctly register ControllerRelProviders
If a String piped into LinkBuilderSupport.slash(…) is empty, the call to UriComponentsBuilder.fromUriString(…) fails with an assertion exception. We now guard against this specific case by returning the current builder instance in case an empty String (potentially returned from the toString() method of the object handed in) would be handed to the UriComponentsBuilder.
The issue was introduced by commit 84efebc7a6.
Commit 8039c306e9 introduced a glitch in ControllerLinkBuilderFactory that caused URIs created not being absolute ones anymore. This commit fixes that glitch.
In case no ObjectMapper bean has been configured explicitly, the Spring MVC infrastructure registers HttpMessageConverters directly and does not declare them as Spring beans. Thus we now also inspect RequestMappingHandlerAdapter and AnnotationMethodHandlerAdapter instances for their HttpMessageConverters and transparently augment the ObjectMappers backing potentially registered Jackson converters.
We now transparently handle "?foo=bar" expressions passed into ….slash(…). Added method to return UriComponentsBuilder to allow more fine grained control over the URI to be built if needed. The dummy method invocations handled to ….linkTo(…) now transparently adds the values handed in for parameters annotated with @RequestParam.
Most of the commit is highly inspired by Dietrich Schultens work at [0]. I just reworked and polished it slightly as we had too many merge conflicts due to related changes in the meantime.
[0] 1ebdc9025a
Introduced new Links container element to group a list of links and allow parsing an RFC5988 compatible String representation of links into it. The parsing mechanism is currently regarding the rel attribute only.
Added valueOf(…) factory methods to allow Spring MVC to pick the types up out of the box.
The annotation registers supporting application components as Spring beans based on the configured hypermedia type. Currently supported are the default rendering as well as HAL. We register a matching LinkDiscoverer implementation as well as the appropriate Jackson modules (if present on the classpath) to support HAL.
Upgraded to Spring 3.1.4 to benefit from fix to prevent multiple invocations of ImportBeanDefinitionRegistrars (see SPR-9939 / SPR-9925).
Introduced UriComponentsContributor interface to allow components to enhance the UriComponentsBuilder used while building links point in to controller methods.
Moved logic from ControllerLinkBuilder into ControllerLinkBuilderFactory as we now potentially need access to Spring injected components. Might be necessary to get rid of the static LinkBuilder implementations entirely.
Added LinkDiscoverer implementation that discovers Links from HAL style representations. Extracted AbstractLinkDiscovererUnitTest to define expected behavior for LinkDiscoverers in general.
If a method level @RequestMapping is not carrying a value we now fall back to the type level mapping as Spring MVC does. Before the fix, providing no mapping lead to an ArrayIndexOutOfBoundsException.
Fixed StackOverflowError in ControllerEntityLinks by delegating to the proper methods now. Clarified contract in EntityLinks interface. Added further unit tests to make sure the implementation behaves like the interface specifies.
Fixes#43.
Extracted Identifiable related code into an IdentifiableResourceAssemblerSupport to be able to use ResourceAssemblerSupport without the need of the domain object to implement Identifiable.