#695 - Remove Jaxb annotations.

By removing all Jaxb annotations, requesting data from a hypermedia-enabled endpoint inside a browser (which defaults to accept:application/xhtml+xml,*/*), Spring HATEOAS will yield HAL.
This commit is contained in:
Greg Turnquist
2018-02-01 16:39:48 -06:00
parent eff893fcf8
commit dca65e15f8
13 changed files with 234 additions and 194 deletions

View File

@@ -30,10 +30,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -47,7 +43,6 @@ import com.fasterxml.jackson.annotation.JsonInclude;
* @author Oliver Gierke
* @author Greg Turnquist
*/
@XmlType(name = "link", namespace = Link.ATOM_NAMESPACE)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value = "templated", ignoreUnknown = true)
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@@ -66,15 +61,15 @@ public class Link implements Serializable {
public static final String REL_NEXT = "next";
public static final String REL_LAST = "last";
private @XmlAttribute @Wither String rel;
private @XmlAttribute @Wither String href;
private @XmlAttribute @Wither String hreflang;
private @XmlAttribute @Wither String media;
private @XmlAttribute @Wither String title;
private @XmlAttribute @Wither String type;
private @XmlAttribute @Wither String deprecation;
private @XmlTransient @JsonIgnore UriTemplate template;
private @XmlTransient @JsonIgnore List<Affordance> affordances;
private @Wither String rel;
private @Wither String href;
private @Wither String hreflang;
private @Wither String media;
private @Wither String title;
private @Wither String type;
private @Wither String deprecation;
private @JsonIgnore UriTemplate template;
private @JsonIgnore List<Affordance> affordances;
/**
* Creates a new link to the given URI with the self rel.

View File

@@ -20,9 +20,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -33,10 +30,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*
* @author Oliver Gierke
*/
@XmlRootElement(name = "pagedEntities")
public class PagedResources<T> extends Resources<T> {
public static PagedResources<?> NO_PAGE = new PagedResources<Object>();
public static PagedResources<?> NO_PAGE = new PagedResources<>();
private PageMetadata metadata;
@@ -169,10 +165,10 @@ public class PagedResources<T> extends Resources<T> {
*/
public static class PageMetadata {
@XmlAttribute @JsonProperty private long size;
@XmlAttribute @JsonProperty private long totalElements;
@XmlAttribute @JsonProperty private long totalPages;
@XmlAttribute @JsonProperty private long number;
@JsonProperty private long size;
@JsonProperty private long totalElements;
@JsonProperty private long totalPages;
@JsonProperty private long number;
protected PageMetadata() {

View File

@@ -18,9 +18,6 @@ package org.springframework.hateoas;
import java.util.Arrays;
import java.util.Collection;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
@@ -31,7 +28,6 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
* @author Oliver Gierke
* @author Greg Turnquist
*/
@XmlRootElement
public class Resource<T> extends ResourceSupport {
private final T content;
@@ -73,7 +69,6 @@ public class Resource<T> extends ResourceSupport {
* @return the content
*/
@JsonUnwrapped
@XmlAnyElement
public T getContent() {
return content;
}

View File

@@ -21,8 +21,6 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -104,7 +102,6 @@ public class ResourceSupport implements Identifiable<Link> {
*
* @return
*/
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
@JsonProperty("links")
public List<Link> getLinks() {
return links;

View File

@@ -21,10 +21,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -34,7 +30,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*
* @author Oliver Gierke
*/
@XmlRootElement(name = "entities")
public class Resources<T> extends ResourceSupport implements Iterable<T> {
private final Collection<T> content;
@@ -98,8 +93,6 @@ public class Resources<T> extends ResourceSupport implements Iterable<T> {
*
* @return the content will never be {@literal null}.
*/
@XmlAnyElement
@XmlElementWrapper
@JsonProperty("content")
public Collection<T> getContent() {
return Collections.unmodifiableCollection(content);

View File

@@ -20,11 +20,6 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -38,10 +33,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
* @see https://github.com/blongden/vnd.error
* @author Oliver Gierke
*/
@XmlRootElement(name = "errors")
public class VndErrors implements Iterable<VndErrors.VndError> {
@XmlElement(name = "error")//
private final List<VndError> vndErrors;
/**
@@ -162,11 +155,10 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
*
* @author Oliver Gierke
*/
@XmlType
public static class VndError extends ResourceSupport {
@XmlAttribute @JsonProperty private final String logref;
@XmlElement @JsonProperty private final String message;
@JsonProperty private final String logref;
@JsonProperty private final String message;
/**
* Creates a new {@link VndError} with the given logref, a message as well as some {@link Link}s.

View File

@@ -17,8 +17,6 @@ package org.springframework.hateoas.hal;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.ResourceSupport;
@@ -38,7 +36,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public abstract class ResourceSupportMixin extends ResourceSupport {
@Override
@XmlElement(name = "link")
@JsonProperty("_links")
@JsonInclude(Include.NON_EMPTY)
@JsonSerialize(using = Jackson2HalModule.HalLinkListSerializer.class)

View File

@@ -17,8 +17,6 @@ package org.springframework.hateoas.hal;
import java.util.Collection;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.hateoas.Resources;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -39,7 +37,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
public abstract class ResourcesMixin<T> extends Resources<T> {
@Override
@XmlElement(name = "embedded")
@JsonProperty("_embedded")
@JsonInclude(Include.NON_EMPTY)
@JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer.class)

View File

@@ -19,8 +19,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.hateoas.Link;
@@ -89,7 +87,6 @@ public class Jackson2HalFormsModule extends SimpleModule {
abstract class ResourcesMixin<T> extends Resources<T> {
@Override
@XmlElement(name = "embedded")
@JsonProperty("_embedded")
@JsonInclude(Include.NON_EMPTY)
@JsonDeserialize(using = HalFormsResourcesDeserializer.class)