Skip to content

Commit b2ad3f6

Browse files
committed
#695 - Remove Jaxb annotations
By removing all Jaxb annotations, subimtted a request for a hypermedia enabled endpoint inside a browser (which defaults to accept:application/xhtml+xml,*/*), Spring HATEOAS will yield HAL.
1 parent 9f7eaee commit b2ad3f6

13 files changed

+234
-194
lines changed

src/main/java/org/springframework/hateoas/Link.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
import java.util.regex.Matcher;
3131
import java.util.regex.Pattern;
3232

33-
import javax.xml.bind.annotation.XmlAttribute;
34-
import javax.xml.bind.annotation.XmlTransient;
35-
import javax.xml.bind.annotation.XmlType;
36-
3733
import org.springframework.util.Assert;
3834
import org.springframework.util.StringUtils;
3935

@@ -47,7 +43,6 @@
4743
* @author Oliver Gierke
4844
* @author Greg Turnquist
4945
*/
50-
@XmlType(name = "link", namespace = Link.ATOM_NAMESPACE)
5146
@JsonInclude(JsonInclude.Include.NON_NULL)
5247
@JsonIgnoreProperties(value = "templated", ignoreUnknown = true)
5348
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@@ -66,15 +61,15 @@ public class Link implements Serializable {
6661
public static final String REL_NEXT = "next";
6762
public static final String REL_LAST = "last";
6863

69-
private @XmlAttribute @Wither String rel;
70-
private @XmlAttribute @Wither String href;
71-
private @XmlAttribute @Wither String hreflang;
72-
private @XmlAttribute @Wither String media;
73-
private @XmlAttribute @Wither String title;
74-
private @XmlAttribute @Wither String type;
75-
private @XmlAttribute @Wither String deprecation;
76-
private @XmlTransient @JsonIgnore UriTemplate template;
77-
private @XmlTransient @JsonIgnore List<Affordance> affordances;
64+
private @Wither String rel;
65+
private @Wither String href;
66+
private @Wither String hreflang;
67+
private @Wither String media;
68+
private @Wither String title;
69+
private @Wither String type;
70+
private @Wither String deprecation;
71+
private @JsonIgnore UriTemplate template;
72+
private @JsonIgnore List<Affordance> affordances;
7873

7974
/**
8075
* Creates a new link to the given URI with the self rel.

src/main/java/org/springframework/hateoas/PagedResources.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.Optional;
2222

23-
import javax.xml.bind.annotation.XmlAttribute;
24-
import javax.xml.bind.annotation.XmlRootElement;
25-
2623
import org.springframework.util.Assert;
2724

2825
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -33,10 +30,9 @@
3330
*
3431
* @author Oliver Gierke
3532
*/
36-
@XmlRootElement(name = "pagedEntities")
3733
public class PagedResources<T> extends Resources<T> {
3834

39-
public static PagedResources<?> NO_PAGE = new PagedResources<Object>();
35+
public static PagedResources<?> NO_PAGE = new PagedResources<>();
4036

4137
private PageMetadata metadata;
4238

@@ -169,10 +165,10 @@ public int hashCode() {
169165
*/
170166
public static class PageMetadata {
171167

172-
@XmlAttribute @JsonProperty private long size;
173-
@XmlAttribute @JsonProperty private long totalElements;
174-
@XmlAttribute @JsonProperty private long totalPages;
175-
@XmlAttribute @JsonProperty private long number;
168+
@JsonProperty private long size;
169+
@JsonProperty private long totalElements;
170+
@JsonProperty private long totalPages;
171+
@JsonProperty private long number;
176172

177173
protected PageMetadata() {
178174

src/main/java/org/springframework/hateoas/Resource.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020

21-
import javax.xml.bind.annotation.XmlAnyElement;
22-
import javax.xml.bind.annotation.XmlRootElement;
23-
2421
import org.springframework.util.Assert;
2522

2623
import com.fasterxml.jackson.annotation.JsonUnwrapped;
@@ -31,7 +28,6 @@
3128
* @author Oliver Gierke
3229
* @author Greg Turnquist
3330
*/
34-
@XmlRootElement
3531
public class Resource<T> extends ResourceSupport {
3632

3733
private final T content;
@@ -73,7 +69,6 @@ public Resource(T content, Iterable<Link> links) {
7369
* @return the content
7470
*/
7571
@JsonUnwrapped
76-
@XmlAnyElement
7772
public T getContent() {
7873
return content;
7974
}

src/main/java/org/springframework/hateoas/ResourceSupport.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.Optional;
2222
import java.util.stream.Collectors;
2323

24-
import javax.xml.bind.annotation.XmlElement;
25-
2624
import org.springframework.util.Assert;
2725

2826
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -104,7 +102,6 @@ public boolean hasLink(String rel) {
104102
*
105103
* @return
106104
*/
107-
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
108105
@JsonProperty("links")
109106
public List<Link> getLinks() {
110107
return links;

src/main/java/org/springframework/hateoas/Resources.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.Iterator;
2323

24-
import javax.xml.bind.annotation.XmlAnyElement;
25-
import javax.xml.bind.annotation.XmlElementWrapper;
26-
import javax.xml.bind.annotation.XmlRootElement;
27-
2824
import org.springframework.util.Assert;
2925

3026
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -34,7 +30,6 @@
3430
*
3531
* @author Oliver Gierke
3632
*/
37-
@XmlRootElement(name = "entities")
3833
public class Resources<T> extends ResourceSupport implements Iterable<T> {
3934

4035
private final Collection<T> content;
@@ -98,8 +93,6 @@ public static <T extends Resource<S>, S> Resources<T> wrap(Iterable<S> content)
9893
*
9994
* @return the content will never be {@literal null}.
10095
*/
101-
@XmlAnyElement
102-
@XmlElementWrapper
10396
@JsonProperty("content")
10497
public Collection<T> getContent() {
10598
return Collections.unmodifiableCollection(content);

src/main/java/org/springframework/hateoas/VndErrors.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
import java.util.Iterator;
2121
import java.util.List;
2222

23-
import javax.xml.bind.annotation.XmlAttribute;
24-
import javax.xml.bind.annotation.XmlElement;
25-
import javax.xml.bind.annotation.XmlRootElement;
26-
import javax.xml.bind.annotation.XmlType;
27-
2823
import org.springframework.util.Assert;
2924
import org.springframework.util.StringUtils;
3025

@@ -38,10 +33,8 @@
3833
* @see https://github.com/blongden/vnd.error
3934
* @author Oliver Gierke
4035
*/
41-
@XmlRootElement(name = "errors")
4236
public class VndErrors implements Iterable<VndErrors.VndError> {
4337

44-
@XmlElement(name = "error")//
4538
private final List<VndError> vndErrors;
4639

4740
/**
@@ -162,11 +155,10 @@ public boolean equals(Object obj) {
162155
*
163156
* @author Oliver Gierke
164157
*/
165-
@XmlType
166158
public static class VndError extends ResourceSupport {
167159

168-
@XmlAttribute @JsonProperty private final String logref;
169-
@XmlElement @JsonProperty private final String message;
160+
@JsonProperty private final String logref;
161+
@JsonProperty private final String message;
170162

171163
/**
172164
* Creates a new {@link VndError} with the given logref, a message as well as some {@link Link}s.

src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.util.List;
1919

20-
import javax.xml.bind.annotation.XmlElement;
21-
2220
import org.springframework.hateoas.Link;
2321
import org.springframework.hateoas.ResourceSupport;
2422

@@ -38,7 +36,6 @@
3836
public abstract class ResourceSupportMixin extends ResourceSupport {
3937

4038
@Override
41-
@XmlElement(name = "link")
4239
@JsonProperty("_links")
4340
@JsonInclude(Include.NON_EMPTY)
4441
@JsonSerialize(using = Jackson2HalModule.HalLinkListSerializer.class)

src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.util.Collection;
1919

20-
import javax.xml.bind.annotation.XmlElement;
21-
2220
import org.springframework.hateoas.Resources;
2321

2422
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -39,7 +37,6 @@
3937
public abstract class ResourcesMixin<T> extends Resources<T> {
4038

4139
@Override
42-
@XmlElement(name = "embedded")
4340
@JsonProperty("_embedded")
4441
@JsonInclude(Include.NON_EMPTY)
4542
@JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer.class)

src/main/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsModule.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import javax.xml.bind.annotation.XmlElement;
23-
2422
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
2523
import org.springframework.context.support.MessageSourceAccessor;
2624
import org.springframework.hateoas.Link;
@@ -89,7 +87,6 @@ static interface ResourceMixin {}
8987
abstract class ResourcesMixin<T> extends Resources<T> {
9088

9189
@Override
92-
@XmlElement(name = "embedded")
9390
@JsonProperty("_embedded")
9491
@JsonInclude(Include.NON_EMPTY)
9592
@JsonDeserialize(using = HalFormsResourcesDeserializer.class)

src/test/java/org/springframework/hateoas/PagedResourcesMarshallingTest.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)