#93 - Fix VndErrors un-marshalling when using Jackson.
Added equals() and hashCode() methods on VndErrors and VndError. Original pull request: #94.
This commit is contained in:
committed by
Oliver Gierke
parent
c5caea5efd
commit
eed331dbe2
@@ -27,8 +27,6 @@ import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* A representation model class to be rendered as specified for the media type {@code application/vnd.error}.
|
||||
*
|
||||
@@ -38,7 +36,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
@XmlRootElement(name = "errors")
|
||||
public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
|
||||
@XmlElement(name = "error")
|
||||
@XmlElement(name = "error")//
|
||||
private final List<VndError> vndErrors;
|
||||
|
||||
/**
|
||||
@@ -68,6 +66,20 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
this.vndErrors.addAll(Arrays.asList(errors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link VndErrors} wrapper for the given {@link VndErrors}.
|
||||
*
|
||||
* @param errors must not be {@literal null} or empty.
|
||||
*/
|
||||
@com.fasterxml.jackson.annotation.JsonCreator
|
||||
@org.codehaus.jackson.annotate.JsonCreator
|
||||
public VndErrors(List<VndError> errors) {
|
||||
|
||||
Assert.notNull(errors, "Errors must not be null!");
|
||||
Assert.isTrue(!errors.isEmpty(), "Errors must not be empty!");
|
||||
this.vndErrors = errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected default constructor to allow JAXB marshalling.
|
||||
*/
|
||||
@@ -96,7 +108,7 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
return vndErrors;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@@ -105,6 +117,34 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
return this.vndErrors.iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return vndErrors.hashCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof VndErrors)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VndErrors that = (VndErrors) obj;
|
||||
return this.vndErrors.equals(that.vndErrors);
|
||||
}
|
||||
|
||||
/**
|
||||
* A single {@link VndError}.
|
||||
*
|
||||
@@ -113,14 +153,14 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
@XmlType
|
||||
public static class VndError extends ResourceSupport {
|
||||
|
||||
@com.fasterxml.jackson.annotation.JsonProperty
|
||||
@org.codehaus.jackson.annotate.JsonProperty
|
||||
@XmlAttribute
|
||||
@com.fasterxml.jackson.annotation.JsonProperty//
|
||||
@org.codehaus.jackson.annotate.JsonProperty//
|
||||
@XmlAttribute//
|
||||
private final String logref;
|
||||
|
||||
@com.fasterxml.jackson.annotation.JsonProperty
|
||||
@org.codehaus.jackson.annotate.JsonProperty
|
||||
@XmlElement
|
||||
@com.fasterxml.jackson.annotation.JsonProperty//
|
||||
@org.codehaus.jackson.annotate.JsonProperty//
|
||||
@XmlElement//
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
@@ -166,5 +206,40 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 17;
|
||||
|
||||
result += 31 * logref.hashCode();
|
||||
result += 31 * message.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof VndError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
VndError that = (VndError) obj;
|
||||
|
||||
return this.logref.equals(that.logref) && this.message.equals(that.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user