#831 - Introduce null handling.
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
@@ -60,7 +61,7 @@ class Rels {
|
||||
* @param mediaType
|
||||
* @return
|
||||
*/
|
||||
Optional<Link> findInResponse(String representation, MediaType mediaType);
|
||||
Optional<Link> findInResponse(@Nullable String representation, @Nullable MediaType mediaType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +142,7 @@ class Rels {
|
||||
* @see org.springframework.hateoas.client.Rels.Rel#findInResponse(java.lang.String, org.springframework.http.MediaType)
|
||||
*/
|
||||
@Override
|
||||
public Optional<Link> findInResponse(String representation, MediaType mediaType) {
|
||||
public Optional<Link> findInResponse(@Nullable String representation, @Nullable MediaType mediaType) {
|
||||
return Optional.of(new Link(JsonPath.read(representation, jsonPath).toString(), rel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
@@ -139,7 +140,7 @@ public class Traverson {
|
||||
* @param operations
|
||||
* @return
|
||||
*/
|
||||
public Traverson setRestOperations(RestOperations operations) {
|
||||
public Traverson setRestOperations(@Nullable RestOperations operations) {
|
||||
|
||||
this.operations = operations == null //
|
||||
? createDefaultTemplate(this.mediaTypes) //
|
||||
@@ -155,7 +156,7 @@ public class Traverson {
|
||||
* @param discoverer can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public Traverson setLinkDiscoverers(List<? extends LinkDiscoverer> discoverer) {
|
||||
public Traverson setLinkDiscoverers(@Nullable List<? extends LinkDiscoverer> discoverer) {
|
||||
|
||||
List<? extends LinkDiscoverer> defaultedDiscoverers = discoverer == null //
|
||||
? DEFAULTS.getLinkDiscoverers(mediaTypes) //
|
||||
@@ -282,6 +283,7 @@ public class Traverson {
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T toObject(Class<T> type) {
|
||||
|
||||
Assert.notNull(type, "Target type must not be null!");
|
||||
@@ -299,6 +301,7 @@ public class Traverson {
|
||||
* @param type must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public <T> T toObject(ParameterizedTypeReference<T> type) {
|
||||
|
||||
Assert.notNull(type, "Target type must not be null!");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/**
|
||||
* Client side support.
|
||||
*/
|
||||
@NonNullApi
|
||||
package org.springframework.hateoas.client;
|
||||
|
||||
import org.springframework.lang.NonNullApi;
|
||||
Reference in New Issue
Block a user