committed by
Oliver Gierke
parent
160afea34d
commit
7570b003d1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.hateoas.IanaRels;
|
||||
import org.springframework.hateoas.Link;
|
||||
@@ -78,16 +77,13 @@ public class DefaultCurieProvider implements CurieProvider {
|
||||
|
||||
Assert.notNull(curies, "Curies must not be null!");
|
||||
|
||||
for (Entry<String, UriTemplate> entry : curies.entrySet()) {
|
||||
|
||||
String name = entry.getKey();
|
||||
UriTemplate template = entry.getValue();
|
||||
curies.forEach((name, template) -> {
|
||||
|
||||
Assert.hasText(name, "Curie name must not be null or empty!");
|
||||
Assert.notNull(template, "UriTemplate must not be null!");
|
||||
Assert.isTrue(template.getVariableNames().size() == 1,
|
||||
String.format("Expected a single template variable in the UriTemplate %s!", template.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
this.defaultCurie = StringUtils.hasText(defaultCurieName) ? defaultCurieName
|
||||
: curies.size() == 1 ? curies.keySet().iterator().next() : null;
|
||||
@@ -101,15 +97,9 @@ public class DefaultCurieProvider implements CurieProvider {
|
||||
@Override
|
||||
public Collection<? extends Object> getCurieInformation(Links links) {
|
||||
|
||||
List<Curie> result = new ArrayList<Curie>(curies.size());
|
||||
List<Curie> result = new ArrayList<>(curies.size());
|
||||
|
||||
for (Entry<String, UriTemplate> source : curies.entrySet()) {
|
||||
|
||||
String name = source.getKey();
|
||||
UriTemplate template = source.getValue();
|
||||
|
||||
result.add(new Curie(name, getCurieHref(name, template)));
|
||||
}
|
||||
curies.forEach((name, template) -> result.add(new Curie(name, getCurieHref(name, template))));
|
||||
|
||||
return Collections.unmodifiableCollection(result);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -152,8 +152,8 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
throws IOException, JsonGenerationException {
|
||||
|
||||
// sort links according to their relation
|
||||
Map<String, List<Object>> sortedLinks = new LinkedHashMap<String, List<Object>>();
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
Map<String, List<Object>> sortedLinks = new LinkedHashMap<>();
|
||||
List<Link> links = new ArrayList<>();
|
||||
|
||||
boolean prefixingRequired = curieProvider != null;
|
||||
boolean curiedLinkPresent = false;
|
||||
@@ -179,18 +179,14 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
curiedLinkPresent = true;
|
||||
}
|
||||
|
||||
if (sortedLinks.get(rel) == null) {
|
||||
sortedLinks.put(rel, new ArrayList<Object>());
|
||||
}
|
||||
sortedLinks.computeIfAbsent(rel, key -> new ArrayList<>()).add(toHalLink(link));
|
||||
|
||||
links.add(link);
|
||||
|
||||
sortedLinks.get(rel).add(toHalLink(link));
|
||||
}
|
||||
|
||||
if (!skipCuries && prefixingRequired && curiedLinkPresent) {
|
||||
|
||||
ArrayList<Object> curies = new ArrayList<Object>();
|
||||
ArrayList<Object> curies = new ArrayList<>();
|
||||
curies.add(curieProvider.getCurieInformation(new Links(links)));
|
||||
|
||||
sortedLinks.put("curies", curies);
|
||||
@@ -414,7 +410,7 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
super(TypeFactory.defaultInstance().constructType(List.class));
|
||||
|
||||
this.property = property;
|
||||
this.serializers = new HashMap<Class<?>, JsonSerializer<Object>>();
|
||||
this.serializers = new HashMap<>();
|
||||
this.halConfiguration = halConfiguration;
|
||||
}
|
||||
|
||||
@@ -559,7 +555,7 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
public List<Link> deserialize(JsonParser jp, DeserializationContext ctxt)
|
||||
throws IOException, JsonProcessingException {
|
||||
|
||||
List<Link> result = new ArrayList<Link>();
|
||||
List<Link> result = new ArrayList<>();
|
||||
String relation;
|
||||
Link link;
|
||||
|
||||
@@ -635,7 +631,7 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
public List<Object> deserialize(JsonParser jp, DeserializationContext ctxt)
|
||||
throws IOException, JsonProcessingException {
|
||||
|
||||
List<Object> result = new ArrayList<Object>();
|
||||
List<Object> result = new ArrayList<>();
|
||||
JsonDeserializer<Object> deser = ctxt.findRootValueDeserializer(contentType);
|
||||
Object object;
|
||||
|
||||
@@ -677,7 +673,7 @@ public class Jackson2HalModule extends SimpleModule {
|
||||
*/
|
||||
public static class HalHandlerInstantiator extends HandlerInstantiator {
|
||||
|
||||
private final Map<Class<?>, Object> serializers = new HashMap<Class<?>, Object>();
|
||||
private final Map<Class<?>, Object> serializers = new HashMap<>();
|
||||
private final AutowireCapableBeanFactory delegate;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user