diff --git a/pom.xml b/pom.xml index 6492850b..7ae14254 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,7 @@ UTF-8 3.2.7.RELEASE 1.0.13 - 1.9.13 - 2.3.0 + 2.3.0 1.0 1.1.1 0.9.1 @@ -135,31 +134,17 @@ provided - - org.codehaus.jackson - jackson-core-asl - ${jackson1.version} - true - - - - org.codehaus.jackson - jackson-mapper-asl - ${jackson1.version} - true - - com.fasterxml.jackson.core jackson-annotations - ${jackson2.version} + ${jackson.version} true com.fasterxml.jackson.core jackson-databind - ${jackson2.version} + ${jackson.version} true diff --git a/src/main/java/org/springframework/hateoas/Link.java b/src/main/java/org/springframework/hateoas/Link.java index 444b25e0..95457ae1 100755 --- a/src/main/java/org/springframework/hateoas/Link.java +++ b/src/main/java/org/springframework/hateoas/Link.java @@ -141,7 +141,6 @@ public class Link implements Serializable { * * @return */ - @org.codehaus.jackson.annotate.JsonIgnore @JsonIgnore public List getVariableNames() { return getUriTemplate().getVariableNames(); @@ -152,7 +151,6 @@ public class Link implements Serializable { * * @return */ - @org.codehaus.jackson.annotate.JsonIgnore @JsonIgnore public List getVariables() { return getUriTemplate().getVariables(); @@ -163,7 +161,6 @@ public class Link implements Serializable { * * @return */ - @org.codehaus.jackson.annotate.JsonIgnore public boolean isTemplated() { return !getUriTemplate().getVariables().isEmpty(); } diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java index ac5332c8..e4b2d44e 100644 --- a/src/main/java/org/springframework/hateoas/PagedResources.java +++ b/src/main/java/org/springframework/hateoas/PagedResources.java @@ -24,6 +24,9 @@ import javax.xml.bind.annotation.XmlRootElement; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * DTO to implement binding response representations of pageable collections. * @@ -71,8 +74,7 @@ public class PagedResources extends Resources { * * @return the metadata */ - @org.codehaus.jackson.annotate.JsonProperty("page") - @com.fasterxml.jackson.annotation.JsonProperty("page") + @JsonProperty("page") public PageMetadata getMetadata() { return metadata; } @@ -103,8 +105,7 @@ public class PagedResources extends Resources { * @see #addPaginationLinks(Link) * @return */ - @com.fasterxml.jackson.annotation.JsonIgnore - @org.codehaus.jackson.annotate.JsonIgnore + @JsonIgnore public Link getNextLink() { return getLink(Link.REL_NEXT); } @@ -115,8 +116,7 @@ public class PagedResources extends Resources { * @see #addPaginationLinks(Link) * @return */ - @com.fasterxml.jackson.annotation.JsonIgnore - @org.codehaus.jackson.annotate.JsonIgnore + @JsonIgnore public Link getPreviousLink() { return getLink(Link.REL_PREVIOUS); } @@ -170,25 +170,10 @@ public class PagedResources extends Resources { */ public static class PageMetadata { - @XmlAttribute// - @org.codehaus.jackson.annotate.JsonProperty// - @com.fasterxml.jackson.annotation.JsonProperty// - private long size; - - @XmlAttribute// - @org.codehaus.jackson.annotate.JsonProperty// - @com.fasterxml.jackson.annotation.JsonProperty// - private long totalElements; - - @XmlAttribute// - @org.codehaus.jackson.annotate.JsonProperty// - @com.fasterxml.jackson.annotation.JsonProperty// - private long totalPages; - - @XmlAttribute// - @org.codehaus.jackson.annotate.JsonProperty// - @com.fasterxml.jackson.annotation.JsonProperty// - private long number; + @XmlAttribute @JsonProperty private long size; + @XmlAttribute @JsonProperty private long totalElements; + @XmlAttribute @JsonProperty private long totalPages; + @XmlAttribute @JsonProperty private long number; protected PageMetadata() { diff --git a/src/main/java/org/springframework/hateoas/Resource.java b/src/main/java/org/springframework/hateoas/Resource.java index 2442b597..17aa48ae 100644 --- a/src/main/java/org/springframework/hateoas/Resource.java +++ b/src/main/java/org/springframework/hateoas/Resource.java @@ -23,6 +23,8 @@ import javax.xml.bind.annotation.XmlRootElement; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonUnwrapped; + /** * A simple {@link Resource} wrapping a domain object and adding links to it. * @@ -69,8 +71,7 @@ public class Resource extends ResourceSupport { * * @return the content */ - @org.codehaus.jackson.annotate.JsonUnwrapped - @com.fasterxml.jackson.annotation.JsonUnwrapped + @JsonUnwrapped @XmlAnyElement public T getContent() { return content; diff --git a/src/main/java/org/springframework/hateoas/ResourceSupport.java b/src/main/java/org/springframework/hateoas/ResourceSupport.java index 9c012b75..ca1351f6 100755 --- a/src/main/java/org/springframework/hateoas/ResourceSupport.java +++ b/src/main/java/org/springframework/hateoas/ResourceSupport.java @@ -22,6 +22,9 @@ import javax.xml.bind.annotation.XmlElement; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * Base class for DTOs to collect links. * @@ -38,8 +41,7 @@ public class ResourceSupport implements Identifiable { /** * Returns the {@link Link} with a rel of {@link Link#REL_SELF}. */ - @org.codehaus.jackson.annotate.JsonIgnore - @com.fasterxml.jackson.annotation.JsonIgnore + @JsonIgnore public Link getId() { return getLink(Link.REL_SELF); } @@ -91,8 +93,7 @@ public class ResourceSupport implements Identifiable { * @return */ @XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE) - @org.codehaus.jackson.annotate.JsonProperty("links") - @com.fasterxml.jackson.annotation.JsonProperty("links") + @JsonProperty("links") public List getLinks() { return links; } diff --git a/src/main/java/org/springframework/hateoas/Resources.java b/src/main/java/org/springframework/hateoas/Resources.java index 8d494f01..04f4142a 100644 --- a/src/main/java/org/springframework/hateoas/Resources.java +++ b/src/main/java/org/springframework/hateoas/Resources.java @@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlRootElement; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * General helper to easily create a wrapper for a collection of entities. * @@ -98,8 +100,7 @@ public class Resources extends ResourceSupport implements Iterable { */ @XmlAnyElement @XmlElementWrapper - @org.codehaus.jackson.annotate.JsonProperty("content") - @com.fasterxml.jackson.annotation.JsonProperty("content") + @JsonProperty("content") public Collection getContent() { return Collections.unmodifiableCollection(content); } diff --git a/src/main/java/org/springframework/hateoas/VndErrors.java b/src/main/java/org/springframework/hateoas/VndErrors.java index 9eb3a5c9..6fc18f32 100644 --- a/src/main/java/org/springframework/hateoas/VndErrors.java +++ b/src/main/java/org/springframework/hateoas/VndErrors.java @@ -28,6 +28,10 @@ import javax.xml.bind.annotation.XmlType; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + /** * A representation model class to be rendered as specified for the media type {@code application/vnd.error}. * @@ -72,8 +76,7 @@ public class VndErrors implements Iterable { * * @param errors must not be {@literal null} or empty. */ - @com.fasterxml.jackson.annotation.JsonCreator - @org.codehaus.jackson.annotate.JsonCreator + @JsonCreator public VndErrors(List errors) { Assert.notNull(errors, "Errors must not be null!"); @@ -103,8 +106,7 @@ public class VndErrors implements Iterable { * * @return the vndErrors */ - @com.fasterxml.jackson.annotation.JsonValue - @org.codehaus.jackson.annotate.JsonValue + @JsonValue private List getErrors() { return vndErrors; } @@ -163,15 +165,8 @@ public class VndErrors implements Iterable { @XmlType public static class VndError extends ResourceSupport { - @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// - private final String message; + @XmlAttribute @JsonProperty private final String logref; + @XmlElement @JsonProperty private final String message; /** * Creates a new {@link VndError} with the given logref, a message as well as some {@link Link}s. diff --git a/src/main/java/org/springframework/hateoas/config/HypermediaSupportBeanDefinitionRegistrar.java b/src/main/java/org/springframework/hateoas/config/HypermediaSupportBeanDefinitionRegistrar.java index 8c99cc81..15ae9a48 100644 --- a/src/main/java/org/springframework/hateoas/config/HypermediaSupportBeanDefinitionRegistrar.java +++ b/src/main/java/org/springframework/hateoas/config/HypermediaSupportBeanDefinitionRegistrar.java @@ -51,11 +51,9 @@ import org.springframework.hateoas.core.DelegatingRelProvider; import org.springframework.hateoas.core.EvoInflectorRelProvider; import org.springframework.hateoas.hal.CurieProvider; import org.springframework.hateoas.hal.HalLinkDiscoverer; -import org.springframework.hateoas.hal.Jackson1HalModule; import org.springframework.hateoas.hal.Jackson2HalModule; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; import org.springframework.plugin.core.PluginRegistry; import org.springframework.plugin.core.support.PluginRegistryFactoryBean; import org.springframework.util.ClassUtils; @@ -78,7 +76,6 @@ class HypermediaSupportBeanDefinitionRegistrar implements ImportBeanDefinitionRe private static final String LINK_DISCOVERER_REGISTRY_BEAN_NAME = "_linkDiscovererRegistry"; private static final String HAL_OBJECT_MAPPER_BEAN_NAME = "_halObjectMapper"; - private static final boolean JACKSON1_PRESENT = ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", null); private static final boolean JACKSON2_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null); private static final boolean JSONPATH_PRESENT = ClassUtils.isPresent("com.jayway.jsonpath.JsonPath", null); @@ -119,11 +116,6 @@ class HypermediaSupportBeanDefinitionRegistrar implements ImportBeanDefinitionRe BeanDefinitionBuilder builder = rootBeanDefinition(Jackson2ModuleRegisteringBeanPostProcessor.class); registerSourcedBeanDefinition(builder, metadata, registry); } - - if (JACKSON1_PRESENT) { - BeanDefinitionBuilder builder = rootBeanDefinition(Jackson1ModuleRegisteringBeanPostProcessor.class); - registerSourcedBeanDefinition(builder, metadata, registry); - } } if (!types.isEmpty()) { @@ -306,76 +298,4 @@ class HypermediaSupportBeanDefinitionRegistrar implements ImportBeanDefinitionRe } } } - - /** - * {@link BeanPostProcessor} to register the {@link Jackson1HalModule} with - * {@link org.codehaus.jackson.map.ObjectMapper} beans registered in the {@link ApplicationContext}. - * - * @author Oliver Gierke - */ - @Deprecated - private static class Jackson1ModuleRegisteringBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware { - - private RelProvider relProvider; - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory) - */ - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.relProvider = beanFactory.getBean(DELEGATING_REL_PROVIDER_BEAN_NAME, RelProvider.class); - } - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - - if (bean instanceof RequestMappingHandlerAdapter) { - - RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean; - adapter.setMessageConverters(registerModule(adapter.getMessageConverters())); - } - - if (bean instanceof AnnotationMethodHandlerAdapter) { - - AnnotationMethodHandlerAdapter adapter = (AnnotationMethodHandlerAdapter) bean; - List> augmentedConverters = registerModule(Arrays - .asList(adapter.getMessageConverters())); - adapter - .setMessageConverters(augmentedConverters.toArray(new HttpMessageConverter[augmentedConverters.size()])); - } - - return bean; - } - - /* - * (non-Javadoc) - * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - private List> registerModule(List> converters) { - - org.codehaus.jackson.map.ObjectMapper objectMapper = new org.codehaus.jackson.map.ObjectMapper(); - - objectMapper.registerModule(new Jackson1HalModule()); - objectMapper.setHandlerInstantiator(new Jackson1HalModule.HalHandlerInstantiator(relProvider)); - - MappingJacksonHttpMessageConverter halConverter = new MappingJacksonHttpMessageConverter(); - halConverter.setSupportedMediaTypes(Arrays.asList(HAL_JSON)); - halConverter.setObjectMapper(objectMapper); - - List> result = new ArrayList>(converters.size()); - result.add(halConverter); - result.addAll(converters); - return result; - } - } } diff --git a/src/main/java/org/springframework/hateoas/hal/Jackson1HalModule.java b/src/main/java/org/springframework/hateoas/hal/Jackson1HalModule.java deleted file mode 100644 index 87c0a81e..00000000 --- a/src/main/java/org/springframework/hateoas/hal/Jackson1HalModule.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright 2012-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.hateoas.hal; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonGenerator; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonProcessingException; -import org.codehaus.jackson.JsonToken; -import org.codehaus.jackson.Version; -import org.codehaus.jackson.map.BeanProperty; -import org.codehaus.jackson.map.ContextualDeserializer; -import org.codehaus.jackson.map.ContextualSerializer; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.DeserializationContext; -import org.codehaus.jackson.map.HandlerInstantiator; -import org.codehaus.jackson.map.JsonDeserializer; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.JsonSerializer; -import org.codehaus.jackson.map.KeyDeserializer; -import org.codehaus.jackson.map.MapperConfig; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.map.SerializerProvider; -import org.codehaus.jackson.map.TypeSerializer; -import org.codehaus.jackson.map.deser.std.ContainerDeserializerBase; -import org.codehaus.jackson.map.introspect.Annotated; -import org.codehaus.jackson.map.jsontype.TypeIdResolver; -import org.codehaus.jackson.map.jsontype.TypeResolverBuilder; -import org.codehaus.jackson.map.module.SimpleModule; -import org.codehaus.jackson.map.ser.std.ContainerSerializerBase; -import org.codehaus.jackson.map.ser.std.MapSerializer; -import org.codehaus.jackson.map.type.TypeFactory; -import org.codehaus.jackson.type.JavaType; -import org.springframework.beans.BeanUtils; -import org.springframework.hateoas.Link; -import org.springframework.hateoas.RelProvider; -import org.springframework.hateoas.Resource; -import org.springframework.hateoas.ResourceSupport; -import org.springframework.hateoas.Resources; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Jackson 1 module implementation to render {@link Link} and {@link ResourceSupport} instances in HAL compatible JSON. - * - * @deprecated use Jackson 2 instead - * @author Alexander Baetz - * @author Oliver Gierke - */ -@Deprecated -public class Jackson1HalModule extends SimpleModule { - - /** - * Creates a new {@link Jackson1HalModule}. - */ - public Jackson1HalModule() { - - super("json-hal-module", new Version(1, 0, 0, null)); - - setMixInAnnotation(Link.class, LinkMixin.class); - setMixInAnnotation(ResourceSupport.class, ResourceSupportMixin.class); - setMixInAnnotation(Resources.class, ResourcesMixin.class); - } - - /** - * Custom {@link JsonSerializer} to render Link instances in HAL compatible JSON. Renders the list as a map, where - * links are sorted based on their relation. - * - * @author Alexander Baetz - * @author Oliver Gierke - */ - public static class HalLinkListSerializer extends ContainerSerializerBase> implements - ContextualSerializer> { - - private final BeanProperty property; - - /** - * Creates a new {@link HalLinkListSerializer}. - */ - public HalLinkListSerializer() { - this(null); - } - - public HalLinkListSerializer(BeanProperty property) { - super(List.class, false); - this.property = property; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ser.std.SerializerBase#serialize(java.lang.Object, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider) - */ - @Override - public void serialize(List value, JsonGenerator jgen, SerializerProvider provider) throws IOException, - JsonGenerationException { - - // sort links according to their relation - Map> sortedLinks = new LinkedHashMap>(); - - for (Link link : value) { - - if (sortedLinks.get(link.getRel()) == null) { - sortedLinks.put(link.getRel(), new ArrayList()); - } - - sortedLinks.get(link.getRel()).add(link); - } - - TypeFactory typeFactory = provider.getConfig().getTypeFactory(); - JavaType keyType = typeFactory.uncheckedSimpleType(String.class); - JavaType valueType = typeFactory.constructCollectionType(ArrayList.class, Link.class); - JavaType mapType = typeFactory.constructMapType(HashMap.class, keyType, valueType); - - MapSerializer serializer = MapSerializer.construct(new String[] {}, mapType, true, null, null, - provider.findKeySerializer(keyType, null), new OptionalListSerializer(property)); - - serializer.serialize(sortedLinks, jgen, provider); - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ContextualSerializer#createContextual(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.BeanProperty) - */ - @Override - public JsonSerializer> createContextual(SerializationConfig config, BeanProperty property) - throws JsonMappingException { - return new HalLinkListSerializer(property); - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ser.std.ContainerSerializerBase#_withValueTypeSerializer(org.codehaus.jackson.map.TypeSerializer) - */ - @Override - public ContainerSerializerBase _withValueTypeSerializer(TypeSerializer vts) { - return null; - } - } - - /** - * Custom {@link JsonSerializer} to render {@link Resource}-Lists in HAL compatible JSON. Renders the list as a Map. - * - * @author Alexander Baetz - * @author Oliver Gierke - */ - public static class HalResourcesSerializer extends ContainerSerializerBase> implements - ContextualSerializer> { - - private final BeanProperty property; - private final RelProvider relProvider; - - /** - * Creates a new {@link HalLinkListSerializer}. - */ - public HalResourcesSerializer(RelProvider relProvider) { - this(null, relProvider); - } - - public HalResourcesSerializer(BeanProperty property, RelProvider relProvider) { - - super(Collection.class, false); - this.property = property; - this.relProvider = relProvider; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ser.std.SerializerBase#serialize(java.lang.Object, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider) - */ - @Override - public void serialize(Collection value, JsonGenerator jgen, SerializerProvider provider) throws IOException, - JsonGenerationException { - - HalEmbeddedBuilder builder = new HalEmbeddedBuilder(relProvider, false); - - for (Object resource : value) { - builder.add(resource); - } - - TypeFactory typeFactory = provider.getConfig().getTypeFactory(); - JavaType keyType = typeFactory.uncheckedSimpleType(String.class); - JavaType valueType = typeFactory.constructCollectionType(ArrayList.class, Resource.class); - JavaType mapType = typeFactory.constructMapType(HashMap.class, keyType, valueType); - - MapSerializer serializer = MapSerializer.construct(new String[] {}, mapType, true, null, null, - provider.findKeySerializer(keyType, null), new OptionalListSerializer(property)); - - serializer.serialize(builder.asMap(), jgen, provider); - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ContextualSerializer#createContextual(org.codehaus.jackson.map.SerializationConfig, org.codehaus.jackson.map.BeanProperty) - */ - @Override - public JsonSerializer> createContextual(SerializationConfig config, BeanProperty property) - throws JsonMappingException { - return new HalResourcesSerializer(property, relProvider); - } - - /* - * (non-Javadoc) - * - * @see org.codehaus.jackson.map.ser.std.ContainerSerializerBase#_withValueTypeSerializer(org.codehaus.jackson.map.TypeSerializer) - */ - @Override - public ContainerSerializerBase _withValueTypeSerializer(TypeSerializer vts) { - return null; - } - } - - /** - * Custom {@link JsonSerializer} to render Objects in HAL compatible JSON. Renders the Object as immediate object if - * we have a single one or as array if we have multiple ones. - * - * @author Alexander Baetz - * @author Oliver Gierke - */ - public static class OptionalListSerializer extends ContainerSerializerBase { - - private final BeanProperty property; - private JsonSerializer serializer; - - public OptionalListSerializer() { - this(null); - } - - public OptionalListSerializer(BeanProperty property) { - - super(List.class, false); - this.property = property; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ser.std.ContainerSerializerBase#_withValueTypeSerializer(org.codehaus.jackson.map.TypeSerializer) - */ - @Override - public ContainerSerializerBase _withValueTypeSerializer(TypeSerializer vts) { - throw new UnsupportedOperationException("Not implemented"); - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ser.std.SerializerBase#serialize(java.lang.Object, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider) - */ - @Override - public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, - JsonGenerationException { - - List list = (List) value; - - if (list.size() == 1) { - serializeContents(list.iterator(), jgen, provider); - return; - } - - jgen.writeStartArray(); - serializeContents(list.iterator(), jgen, provider); - jgen.writeEndArray(); - } - - private void serializeContents(Iterator value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonGenerationException { - - while (value.hasNext()) { - Object elem = value.next(); - if (elem == null) { - provider.defaultSerializeNull(jgen); - } else { - if (serializer == null) { - serializer = provider.findValueSerializer(elem.getClass(), property); - } - serializer.serialize(elem, jgen, provider); - } - } - } - } - - public static class HalLinkListDeserializer extends ContainerDeserializerBase> { - - public HalLinkListDeserializer() { - super(List.class); - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.deser.std.ContainerDeserializerBase#getContentType() - */ - @Override - public JavaType getContentType() { - return null; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.deser.std.ContainerDeserializerBase#getContentDeserializer() - */ - @Override - public JsonDeserializer getContentDeserializer() { - return null; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson.JsonParser, org.codehaus.jackson.map.DeserializationContext) - */ - @Override - public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, - JsonProcessingException { - - List result = new ArrayList(); - - // links is an object, so we parse till we find its end. - while (!JsonToken.END_OBJECT.equals(jp.nextToken())) { - - if (!JsonToken.FIELD_NAME.equals(jp.getCurrentToken())) { - throw new JsonParseException("Expected relation name", jp.getCurrentLocation()); - } - - // save the relation in case the link does not contain it - String relation = jp.getText(); - - if (JsonToken.START_ARRAY.equals(jp.nextToken())) { - while (!JsonToken.END_ARRAY.equals(jp.nextToken())) { - result.add(getDefaultedLink(jp, relation)); - } - } else { - result.add(getDefaultedLink(jp, relation)); - } - } - - return result; - } - - private Link getDefaultedLink(JsonParser parser, String relation) throws JsonProcessingException, IOException { - - Link link = parser.readValueAs(Link.class); - return StringUtils.hasText(link.getRel()) ? link : new Link(link.getHref(), relation); - } - } - - public static class HalResourcesDeserializer extends ContainerDeserializerBase> implements - ContextualDeserializer> { - - private final JavaType contentType; - - public HalResourcesDeserializer() { - this(List.class, null); - } - - public HalResourcesDeserializer(JavaType vc) { - this(null, vc); - } - - private HalResourcesDeserializer(Class type, JavaType contentType) { - - super(type); - this.contentType = contentType; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.deser.std.ContainerDeserializerBase#getContentType() - */ - @Override - public JavaType getContentType() { - return null; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.deser.std.ContainerDeserializerBase#getContentDeserializer() - */ - @Override - public JsonDeserializer getContentDeserializer() { - return null; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson.JsonParser, org.codehaus.jackson.map.DeserializationContext) - */ - @Override - public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, - JsonProcessingException { - - List result = new ArrayList(); - JsonDeserializer deser = ctxt.getDeserializerProvider().findTypedValueDeserializer(ctxt.getConfig(), - contentType, null); - Object object; - - // links is an object, so we parse till we find its end. - while (!JsonToken.END_OBJECT.equals(jp.nextToken())) { - - if (!JsonToken.FIELD_NAME.equals(jp.getCurrentToken())) { - throw new JsonParseException("Expected relation name", jp.getCurrentLocation()); - } - - if (JsonToken.START_ARRAY.equals(jp.nextToken())) { - while (!JsonToken.END_ARRAY.equals(jp.nextToken())) { - object = deser.deserialize(jp, ctxt); - result.add(object); - } - } else { - object = deser.deserialize(jp, ctxt); - result.add(object); - } - } - - return result; - } - - /* - * (non-Javadoc) - * @see org.codehaus.jackson.map.ContextualDeserializer#createContextual(org.codehaus.jackson.map.DeserializationConfig, org.codehaus.jackson.map.BeanProperty) - */ - @Override - public JsonDeserializer> createContextual(DeserializationConfig config, BeanProperty property) - throws JsonMappingException { - - JavaType vc = property.getType().getContentType(); - HalResourcesDeserializer des = new HalResourcesDeserializer(vc); - return des; - } - } - - public static class HalHandlerInstantiator extends HandlerInstantiator { - - private final Map, Object> instanceMap = new HashMap, Object>(); - - public HalHandlerInstantiator(RelProvider relProvider) { - - Assert.notNull(relProvider, "RelProvider must not be null!"); - this.instanceMap.put(HalResourcesSerializer.class, new HalResourcesSerializer(null, relProvider)); - - } - - @Override - public JsonDeserializer deserializerInstance(DeserializationConfig config, Annotated annotated, - Class> deserClass) { - return (JsonDeserializer) findInstance(deserClass, false); - } - - @Override - public KeyDeserializer keyDeserializerInstance(DeserializationConfig config, Annotated annotated, - Class keyDeserClass) { - return (KeyDeserializer) findInstance(keyDeserClass, false); - } - - @Override - public JsonSerializer serializerInstance(SerializationConfig config, Annotated annotated, - Class> serClass) { - // there is a know bug in jackson that will not create a serializer instance if the handler instantiator returns - // null! - return (JsonSerializer) findInstance(serClass, true); - } - - @Override - public TypeResolverBuilder typeResolverBuilderInstance(MapperConfig config, Annotated annotated, - Class> builderClass) { - return (TypeResolverBuilder) findInstance(builderClass, false); - } - - @Override - public TypeIdResolver typeIdResolverInstance(MapperConfig config, Annotated annotated, - Class resolverClass) { - return (TypeIdResolver) findInstance(resolverClass, false); - } - - private Object findInstance(Class type, boolean createInstance) { - - Object result = instanceMap.get(type); - - if (result != null) { - return result; - } - - return createInstance ? BeanUtils.instantiateClass(type) : null; - } - } -} diff --git a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java index 493f89ae..53f796eb 100644 --- a/src/main/java/org/springframework/hateoas/hal/LinkMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/LinkMixin.java @@ -18,6 +18,7 @@ package org.springframework.hateoas.hal; import org.springframework.hateoas.Link; import org.springframework.hateoas.hal.Jackson2HalModule.TrueOnlyBooleanSerializer; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -28,8 +29,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; * @author Alexander Baetz * @author Oliver Gierke */ -@org.codehaus.jackson.annotate.JsonIgnoreProperties(value = "rel") -@com.fasterxml.jackson.annotation.JsonIgnoreProperties(value = "rel") +@JsonIgnoreProperties(value = "rel") abstract class LinkMixin extends Link { private static final long serialVersionUID = 4720588561299667409L; diff --git a/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java b/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java index 2ce8c829..0e2d5475 100644 --- a/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java @@ -22,22 +22,16 @@ import javax.xml.bind.annotation.XmlElement; import org.springframework.hateoas.Link; import org.springframework.hateoas.ResourceSupport; -@SuppressWarnings("deprecation") +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + abstract class ResourceSupportMixin extends ResourceSupport { @Override @XmlElement(name = "link") - @org.codehaus.jackson.annotate.JsonProperty("_links") - @com.fasterxml.jackson.annotation.JsonProperty("_links") - @org.codehaus.jackson.map.annotate.JsonSerialize( - include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY, - using = org.springframework.hateoas.hal.Jackson1HalModule.HalLinkListSerializer.class) - @org.codehaus.jackson.map.annotate.JsonDeserialize( - using = org.springframework.hateoas.hal.Jackson1HalModule.HalLinkListDeserializer.class) - @com.fasterxml.jackson.databind.annotation.JsonSerialize( - include = com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_EMPTY, - using = org.springframework.hateoas.hal.Jackson2HalModule.HalLinkListSerializer.class) - @com.fasterxml.jackson.databind.annotation.JsonDeserialize( - using = org.springframework.hateoas.hal.Jackson2HalModule.HalLinkListDeserializer.class) + @JsonProperty("_links") + @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY, using = Jackson2HalModule.HalLinkListSerializer.class) + @JsonDeserialize(using = Jackson2HalModule.HalLinkListDeserializer.class) public abstract List getLinks(); } diff --git a/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java b/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java index b7ad6b3c..e95d0735 100644 --- a/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java @@ -21,23 +21,17 @@ import javax.xml.bind.annotation.XmlElement; import org.springframework.hateoas.Resources; -@SuppressWarnings("deprecation") +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + public abstract class ResourcesMixin extends Resources { @Override @XmlElement(name = "embedded") - @org.codehaus.jackson.annotate.JsonProperty("_embedded") - @com.fasterxml.jackson.annotation.JsonProperty("_embedded") - @org.codehaus.jackson.map.annotate.JsonSerialize( - include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_EMPTY, - using = org.springframework.hateoas.hal.Jackson1HalModule.HalResourcesSerializer.class) - @org.codehaus.jackson.map.annotate.JsonDeserialize( - using = org.springframework.hateoas.hal.Jackson1HalModule.HalResourcesDeserializer.class) - @com.fasterxml.jackson.databind.annotation.JsonSerialize( - include = com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion.NON_EMPTY, - using = org.springframework.hateoas.hal.Jackson2HalModule.HalResourcesSerializer.class) - @com.fasterxml.jackson.databind.annotation.JsonDeserialize( - using = org.springframework.hateoas.hal.Jackson2HalModule.HalResourcesDeserializer.class) + @JsonProperty("_embedded") + @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY, using = Jackson2HalModule.HalResourcesSerializer.class) + @JsonDeserialize(using = Jackson2HalModule.HalResourcesDeserializer.class) public abstract Collection getContent(); } diff --git a/src/test/java/org/springframework/hateoas/AbstractMarshallingIntegrationTest.java b/src/test/java/org/springframework/hateoas/AbstractMarshallingIntegrationTest.java deleted file mode 100644 index b04a1141..00000000 --- a/src/test/java/org/springframework/hateoas/AbstractMarshallingIntegrationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.hateoas; - -import java.io.StringWriter; -import java.io.Writer; - -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Before; - -/** - * Base class to eas integration tests for {@link ObjectMapper} marshalling. - * - * @author Oliver Gierke - */ -public abstract class AbstractMarshallingIntegrationTest { - - protected ObjectMapper mapper; - - @Before - public void setUp() { - mapper = new ObjectMapper(); - } - - protected String write(Object object) throws Exception { - - Writer writer = new StringWriter(); - mapper.writeValue(writer, object); - return writer.toString(); - } - - protected T read(String source, Class targetType) throws Exception { - return mapper.readValue(source, targetType); - } -} diff --git a/src/test/java/org/springframework/hateoas/LinkIntegrationTest.java b/src/test/java/org/springframework/hateoas/LinkIntegrationTest.java index 7f2409a4..fd806c08 100644 --- a/src/test/java/org/springframework/hateoas/LinkIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/LinkIntegrationTest.java @@ -25,7 +25,7 @@ import org.junit.Test; * * @author Oliver Gierke */ -public class LinkIntegrationTest extends AbstractMarshallingIntegrationTest { +public class LinkIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { private static final String REFERENCE = "{\"rel\":\"something\",\"href\":\"location\"}"; diff --git a/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java b/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java index d2874096..2a6a7402 100644 --- a/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java @@ -25,19 +25,20 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; -import org.codehaus.jackson.annotate.JsonAutoDetect; -import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility; import org.custommonkey.xmlunit.Diff; import org.junit.Test; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + /** * Integration tests for {@link Resource}. * * @author Oliver Gierke */ -public class ResourceIntegrationTest extends AbstractMarshallingIntegrationTest { +public class ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { - static final String REFERENCE = "{\"links\":[{\"rel\":\"self\",\"href\":\"localhost\"}],\"firstname\":\"Dave\",\"lastname\":\"Matthews\"}"; + static final String REFERENCE = "{\"firstname\":\"Dave\",\"lastname\":\"Matthews\",\"links\":[{\"rel\":\"self\",\"href\":\"localhost\"}]}"; static final String XML_REFERENCE = ""; @Test diff --git a/src/test/java/org/springframework/hateoas/ResourceSupportIntegrationTest.java b/src/test/java/org/springframework/hateoas/ResourceSupportIntegrationTest.java index 9f6fdb3b..ffc6ce86 100644 --- a/src/test/java/org/springframework/hateoas/ResourceSupportIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/ResourceSupportIntegrationTest.java @@ -25,7 +25,7 @@ import org.junit.Test; * * @author Oliver Gierke */ -public class ResourceSupportIntegrationTest extends AbstractMarshallingIntegrationTest { +public class ResourceSupportIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { static final String REFERENCE = "{\"links\":[{\"rel\":\"self\",\"href\":\"localhost\"}]}"; diff --git a/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java b/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java index 10f97f7f..e75063f0 100644 --- a/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java +++ b/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java @@ -31,17 +31,15 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig.Feature; import org.custommonkey.xmlunit.Diff; import org.junit.Before; import org.junit.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.hateoas.VndErrors.VndError; import org.springframework.hateoas.core.EvoInflectorRelProvider; -import org.springframework.hateoas.hal.Jackson1HalModule; import org.springframework.hateoas.hal.Jackson2HalModule; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; /** @@ -52,8 +50,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; @SuppressWarnings("deprecation") public class VndErrorsMarshallingTest { - ObjectMapper jackson1Mapper; - com.fasterxml.jackson.databind.ObjectMapper jackson2Mapper; + ObjectMapper jackson2Mapper; Marshaller marshaller; Unmarshaller unmarshaller; @@ -74,10 +71,6 @@ public class VndErrorsMarshallingTest { @Before public void setUp() throws Exception { - jackson1Mapper = new ObjectMapper(); - jackson1Mapper.registerModule(new Jackson1HalModule()); - jackson1Mapper.configure(Feature.INDENT_OUTPUT, true); - jackson2Mapper = new com.fasterxml.jackson.databind.ObjectMapper(); jackson2Mapper.registerModule(new Jackson2HalModule()); jackson2Mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(relProvider, null)); @@ -92,14 +85,6 @@ public class VndErrorsMarshallingTest { errors = new VndErrors(error, error, error); } - /** - * @see #62 - */ - @Test - public void jackson1Marshalling() throws Exception { - assertThat(jackson1Mapper.writeValueAsString(errors), is(jsonReference)); - } - /** * @see #62 */ @@ -120,15 +105,6 @@ public class VndErrorsMarshallingTest { assertThat(new Diff(xmlReference, writer.toString()).similar(), is(true)); } - /** - * @see #62, #93, #94 - */ - @Test - public void jackson1UnMarshalling() throws Exception { - VndErrors actual = jackson1Mapper.readValue(jsonReference, VndErrors.class); - assertThat(actual, is(errors)); - } - /** * @see #93, #94 */ diff --git a/src/test/java/org/springframework/hateoas/config/EnableHypermediaSupportIntegrationTest.java b/src/test/java/org/springframework/hateoas/config/EnableHypermediaSupportIntegrationTest.java index e6916f8b..c8f05fdb 100644 --- a/src/test/java/org/springframework/hateoas/config/EnableHypermediaSupportIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/config/EnableHypermediaSupportIntegrationTest.java @@ -43,7 +43,6 @@ import org.springframework.hateoas.core.DelegatingRelProvider; import org.springframework.hateoas.hal.HalLinkDiscoverer; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter; @@ -103,12 +102,12 @@ public class EnableHypermediaSupportIntegrationTest { assertThat(context.getBean(ObjectMapper.class), is(notNullValue())); RequestMappingHandlerAdapter rmha = context.getBean(RequestMappingHandlerAdapter.class); - assertThat(rmha.getMessageConverters(), Matchers.> hasItems( - instanceOf(MappingJackson2HttpMessageConverter.class), instanceOf(MappingJacksonHttpMessageConverter.class))); + assertThat(rmha.getMessageConverters(), + Matchers.> hasItems(instanceOf(MappingJackson2HttpMessageConverter.class))); AnnotationMethodHandlerAdapter amha = context.getBean(AnnotationMethodHandlerAdapter.class); - assertThat(Arrays.asList(amha.getMessageConverters()), Matchers.> hasItems( - instanceOf(MappingJackson2HttpMessageConverter.class), instanceOf(MappingJacksonHttpMessageConverter.class))); + assertThat(Arrays.asList(amha.getMessageConverters()), + Matchers.> hasItems(instanceOf(MappingJackson2HttpMessageConverter.class))); } /** diff --git a/src/test/java/org/springframework/hateoas/hal/Jackson1HalIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/Jackson1HalIntegrationTest.java deleted file mode 100644 index c480d6dc..00000000 --- a/src/test/java/org/springframework/hateoas/hal/Jackson1HalIntegrationTest.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2012-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.hateoas.hal; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.hateoas.AbstractMarshallingIntegrationTest; -import org.springframework.hateoas.Link; -import org.springframework.hateoas.Links; -import org.springframework.hateoas.PagedResources; -import org.springframework.hateoas.PagedResources.PageMetadata; -import org.springframework.hateoas.Resource; -import org.springframework.hateoas.ResourceSupport; -import org.springframework.hateoas.Resources; -import org.springframework.hateoas.core.AnnotationRelProvider; -import org.springframework.hateoas.hal.Jackson1HalModule.HalHandlerInstantiator; - -/** - * Integration tests for Jackson 1 based HAL integration. - * - * @author Alexander Baetz - * @author Oliver Gierke - */ -@SuppressWarnings("deprecation") -public class Jackson1HalIntegrationTest extends AbstractMarshallingIntegrationTest { - - static final String SINGLE_LINK_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}}}"; - static final String LIST_LINK_REFERENCE = "{\"_links\":{\"self\":[{\"href\":\"localhost\"},{\"href\":\"localhost2\"}]}}"; - - static final String SIMPLE_EMBEDDED_RESOURCE_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}},\"_embedded\":{\"content\":[\"first\",\"second\"]}}"; - static final String SINGLE_EMBEDDED_RESOURCE_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}},\"_embedded\":{\"content\":{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}}}}"; - static final String LIST_EMBEDDED_RESOURCE_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}},\"_embedded\":{\"content\":[{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}},{\"text\":\"test2\",\"number\":2,\"_links\":{\"self\":{\"href\":\"localhost\"}}}]}}"; - - static final String ANNOTATED_EMBEDDED_RESOURCE_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}},\"_embedded\":{\"pojo\":{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}}}}"; - static final String ANNOTATED_EMBEDDED_RESOURCES_REFERENCE = "{\"_embedded\":{\"pojos\":[{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}},{\"text\":\"test2\",\"number\":2,\"_links\":{\"self\":{\"href\":\"localhost\"}}}]}}"; - - static final String ANNOTATED_PAGED_RESOURCES = "{\"_links\":{\"next\":{\"href\":\"foo\"},\"prev\":{\"href\":\"bar\"}},\"_embedded\":{\"pojos\":[{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}},{\"text\":\"test2\",\"number\":2,\"_links\":{\"self\":{\"href\":\"localhost\"}}}]},\"page\":{\"size\":2,\"totalElements\":4,\"totalPages\":2,\"number\":0}}"; - - static final Links PAGINATION_LINKS = new Links(new Link("foo", Link.REL_NEXT), new Link("bar", Link.REL_PREVIOUS)); - - @Before - public void setUpModule() { - - mapper.registerModule(new Jackson1HalModule()); - mapper.setHandlerInstantiator(new HalHandlerInstantiator(new AnnotationRelProvider())); - } - - /** - * @see #29 - */ - @Test - public void rendersSingleLinkAsObject() throws Exception { - - ResourceSupport resourceSupport = new ResourceSupport(); - resourceSupport.add(new Link("localhost")); - - assertThat(write(resourceSupport), is(SINGLE_LINK_REFERENCE)); - } - - @Test - public void deserializeSingleLink() throws Exception { - - ResourceSupport expected = new ResourceSupport(); - expected.add(new Link("localhost")); - - assertThat(read(SINGLE_LINK_REFERENCE, ResourceSupport.class), is(expected)); - } - - /** - * @see #29 - */ - @Test - public void rendersMultipleLinkAsArray() throws Exception { - - ResourceSupport resourceSupport = new ResourceSupport(); - resourceSupport.add(new Link("localhost")); - resourceSupport.add(new Link("localhost2")); - - assertThat(write(resourceSupport), is(LIST_LINK_REFERENCE)); - } - - @Test - public void deserializeMultipleLinks() throws Exception { - - ResourceSupport expected = new ResourceSupport(); - expected.add(new Link("localhost")); - expected.add(new Link("localhost2")); - - assertThat(read(LIST_LINK_REFERENCE, ResourceSupport.class), is(expected)); - } - - @Test - public void rendersSimpleResourcesAsEmbedded() throws Exception { - - List content = new ArrayList(); - content.add("first"); - content.add("second"); - - Resources resources = new Resources(content); - resources.add(new Link("localhost")); - - assertThat(write(resources), is(SIMPLE_EMBEDDED_RESOURCE_REFERENCE)); - } - - @Test - public void deserializesSimpleResourcesAsEmbedded() throws Exception { - - List content = new ArrayList(); - content.add("first"); - content.add("second"); - - Resources expected = new Resources(content); - expected.add(new Link("localhost")); - - Resources result = mapper.readValue(SIMPLE_EMBEDDED_RESOURCE_REFERENCE, mapper.getTypeFactory() - .constructParametricType(Resources.class, String.class)); - - assertThat(result, is(expected)); - } - - @Test - public void rendersSingleResourceResourcesAsEmbedded() throws Exception { - - List> content = new ArrayList>(); - content.add(new Resource(new SimplePojo("test1", 1), new Link("localhost"))); - - Resources> resources = new Resources>(content); - resources.add(new Link("localhost")); - - assertThat(write(resources), is(SINGLE_EMBEDDED_RESOURCE_REFERENCE)); - } - - @Test - public void deserializesSingleResourceResourcesAsEmbedded() throws Exception { - - List> content = new ArrayList>(); - content.add(new Resource(new SimplePojo("test1", 1), new Link("localhost"))); - - Resources> expected = new Resources>(content); - expected.add(new Link("localhost")); - - Resources> result = mapper.readValue( - SINGLE_EMBEDDED_RESOURCE_REFERENCE, - mapper.getTypeFactory().constructParametricType(Resources.class, - mapper.getTypeFactory().constructParametricType(Resource.class, SimplePojo.class))); - - assertThat(result, is(expected)); - } - - @Test - public void rendersMultipleResourceResourcesAsEmbedded() throws Exception { - - Resources> resources = setupResources(); - resources.add(new Link("localhost")); - - assertThat(write(resources), is(LIST_EMBEDDED_RESOURCE_REFERENCE)); - } - - @Test - public void deserializeMultipleResourceResourcesAsEmbedded() throws Exception { - - Resources> expected = setupResources(); - expected.add(new Link("localhost")); - - Resources> result = mapper.readValue( - LIST_EMBEDDED_RESOURCE_REFERENCE, - mapper.getTypeFactory().constructParametricType(Resources.class, - mapper.getTypeFactory().constructParametricType(Resource.class, SimplePojo.class))); - - assertThat(result, is(expected)); - } - - @Test - public void rendersAnnotatedResourceResourcesAsEmbedded() throws Exception { - - List> content = new ArrayList>(); - content.add(new Resource(new SimpleAnnotatedPojo("test1", 1), new Link("localhost"))); - - Resources> resources = new Resources>(content); - resources.add(new Link("localhost")); - - assertThat(write(resources), is(ANNOTATED_EMBEDDED_RESOURCE_REFERENCE)); - } - - @Test - public void deserializesAnnotatedResourceResourcesAsEmbedded() throws Exception { - - List> content = new ArrayList>(); - content.add(new Resource(new SimpleAnnotatedPojo("test1", 1), new Link("localhost"))); - - Resources> expected = new Resources>(content); - expected.add(new Link("localhost")); - - Resources> result = mapper.readValue( - ANNOTATED_EMBEDDED_RESOURCE_REFERENCE, - mapper.getTypeFactory().constructParametricType(Resources.class, - mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class))); - - assertThat(result, is(expected)); - } - - /** - * @see #63 - */ - @Test - public void serializesMultipleAnnotatedResourceResourcesAsEmbedded() throws Exception { - assertThat(write(setupAnnotatedResources()), is(ANNOTATED_EMBEDDED_RESOURCES_REFERENCE)); - } - - /** - * @see #63 - */ - @Test - public void deserializesMultipleAnnotatedResourceResourcesAsEmbedded() throws Exception { - - Resources> result = mapper.readValue( - ANNOTATED_EMBEDDED_RESOURCES_REFERENCE, - mapper.getTypeFactory().constructParametricType(Resources.class, - mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class))); - - assertThat(result, is(setupAnnotatedResources())); - } - - @Test - public void serializesPagedResource() throws Exception { - assertThat(write(setupAnnotatedPagedResources()), is(ANNOTATED_PAGED_RESOURCES)); - } - - @Test - public void deserializesPagedResource() throws Exception { - PagedResources> result = mapper.readValue( - ANNOTATED_PAGED_RESOURCES, - mapper.getTypeFactory().constructParametricType(PagedResources.class, - mapper.getTypeFactory().constructParametricType(Resource.class, SimpleAnnotatedPojo.class))); - - assertThat(result, is(setupAnnotatedPagedResources())); - } - - private static Resources> setupAnnotatedPagedResources() { - - List> content = new ArrayList>(); - content.add(new Resource(new SimpleAnnotatedPojo("test1", 1), new Link("localhost"))); - content.add(new Resource(new SimpleAnnotatedPojo("test2", 2), new Link("localhost"))); - - return new PagedResources>(content, new PageMetadata(2, 0, 4), PAGINATION_LINKS); - } - - private static Resources> setupAnnotatedResources() { - - List> content = new ArrayList>(); - content.add(new Resource(new SimpleAnnotatedPojo("test1", 1), new Link("localhost"))); - content.add(new Resource(new SimpleAnnotatedPojo("test2", 2), new Link("localhost"))); - - return new Resources>(content); - } - - private static Resources> setupResources() { - - List> content = new ArrayList>(); - content.add(new Resource(new SimplePojo("test1", 1), new Link("localhost"))); - content.add(new Resource(new SimplePojo("test2", 2), new Link("localhost"))); - - return new Resources>(content); - } -} diff --git a/template.mf b/template.mf index 17418b65..09248052 100644 --- a/template.mf +++ b/template.mf @@ -3,7 +3,7 @@ Bundle-Name: Spring HATEOAS Bundle-Vendor: SpringSource Bundle-ManifestVersion: 2 Import-Template: - com.fasterxml.jackson.*;version="${jackson2.version:[=.=.=,+1.0.0)}";resolution:=optional, + com.fasterxml.jackson.*;version="${jackson.version:[=.=.=,+1.0.0)}";resolution:=optional, com.jayway.jsonpath.*;version="${jsonpath.version:[=.=.=,+1.0.0)}";resolution:=optional, javax.servlet.*;version="[2.5,4.0)";resolution:=optional, javax.ws.rs.*;version="${jaxrs.version:[=.=.=,+1.0.0)}";resolution:=optional, @@ -13,5 +13,4 @@ Import-Template: org.atteo.evo.inflector.*;version="${evo.version:[=.=.=,+1.0.0)}";resolution:=optional, org.objenesis.*;version="${objenesis.version:[=.=.=,+1.0.0)}", org.springframework.plugin.*;version="[0.8.0,2.0.0)";resolution:=optional, - org.springframework.*;version="${spring.version:[=.=.=,+1.1.0)}";resolution:=optional, - org.codehaus.jackson.*;version="${jackson1.version:[=.=.=,+1.0.0)}";resolution:=optional + org.springframework.*;version="${spring.version:[=.=.=,+1.1.0)}";resolution:=optional