From 33ad2e0947140de2b4184262e6d1c2067bde0735 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 20 May 2016 14:12:34 +0200 Subject: [PATCH] #455 - Adapt Jackson2HalModule to assure Jackson 2.7 compatibility. Changed invocations of constructors of the super class in Jackson Serializers to use JavaType instead of Class as the constructor has been removed in some of the base classes in Jackson 2.7. Upgraded to Jackson 2.5.5 along the way. --- pom.xml | 2 +- .../hateoas/hal/Jackson2HalModule.java | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index b6346ad6..57758cdb 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ UTF-8 4.1.7.RELEASE 1.1.3 - 2.5.4 + 2.5.5 2.0.1 2.2 2.0.0 diff --git a/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java b/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java index bb0f4a82..aa4f23c8 100644 --- a/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java +++ b/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -112,7 +112,9 @@ public class Jackson2HalModule extends SimpleModule { * @author Alexander Baetz * @author Oliver Gierke */ - public static class HalLinkListSerializer extends ContainerSerializer>implements ContextualSerializer { + public static class HalLinkListSerializer extends ContainerSerializer> implements ContextualSerializer { + + private static final long serialVersionUID = -1844788111509966406L; private static final String RELATION_MESSAGE_TEMPLATE = "_links.%s.title"; @@ -129,7 +131,8 @@ public class Jackson2HalModule extends SimpleModule { public HalLinkListSerializer(BeanProperty property, CurieProvider curieProvider, EmbeddedMapper mapper, MessageSourceAccessor messageSource) { - super(List.class, false); + super(TypeFactory.defaultInstance().constructType(List.class)); + this.property = property; this.curieProvider = curieProvider; this.mapper = mapper; @@ -306,7 +309,10 @@ public class Jackson2HalModule extends SimpleModule { * @author Alexander Baetz * @author Oliver Gierke */ - public static class HalResourcesSerializer extends ContainerSerializer>implements ContextualSerializer { + public static class HalResourcesSerializer extends ContainerSerializer> + implements ContextualSerializer { + + private static final long serialVersionUID = 8030706944344625390L; private final BeanProperty property; private final EmbeddedMapper embeddedMapper; @@ -317,7 +323,7 @@ public class Jackson2HalModule extends SimpleModule { public HalResourcesSerializer(BeanProperty property, EmbeddedMapper embeddedMapper) { - super(Collection.class, false); + super(TypeFactory.defaultInstance().constructType(Collection.class)); this.property = property; this.embeddedMapper = embeddedMapper; @@ -392,6 +398,8 @@ public class Jackson2HalModule extends SimpleModule { public static class OptionalListJackson2Serializer extends ContainerSerializer implements ContextualSerializer { + private static final long serialVersionUID = 3700806118177419817L; + private final BeanProperty property; private final Map, JsonSerializer> serializers; @@ -406,7 +414,8 @@ public class Jackson2HalModule extends SimpleModule { */ public OptionalListJackson2Serializer(BeanProperty property) { - super(List.class, false); + super(TypeFactory.defaultInstance().constructType(List.class)); + this.property = property; this.serializers = new HashMap, JsonSerializer>(); } @@ -531,9 +540,8 @@ public class Jackson2HalModule extends SimpleModule { private static final long serialVersionUID = 6420432361123210955L; - @SuppressWarnings("deprecation") public HalLinkListDeserializer() { - super(List.class); + super(TypeFactory.defaultInstance().constructCollectionLikeType(List.class, Link.class)); } /* @@ -598,15 +606,14 @@ public class Jackson2HalModule extends SimpleModule { private JavaType contentType; public HalResourcesDeserializer() { - this(List.class, null); + this(TypeFactory.defaultInstance().constructCollectionLikeType(List.class, Object.class), null); } public HalResourcesDeserializer(JavaType vc) { this(null, vc); } - @SuppressWarnings("deprecation") - private HalResourcesDeserializer(Class type, JavaType contentType) { + private HalResourcesDeserializer(JavaType type, JavaType contentType) { super(type); this.contentType = contentType; @@ -756,6 +763,8 @@ public class Jackson2HalModule extends SimpleModule { */ public static class TrueOnlyBooleanSerializer extends NonTypedScalarSerializerBase { + private static final long serialVersionUID = 5817795880782727569L; + public TrueOnlyBooleanSerializer() { super(Boolean.class); }