Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit ceb94a1

Browse files
author
Michal Gajdos
committed
J-329: Update MOXy to version 2.6
- Updated MOXy (2.5.0 -> 2.6.0) - Unignored some tests (ignored one other test) - Modified OSGi test (disable BV in MOXy) - Updated Migration Guide Change-Id: Ieccb926bfa750e06b31e898af86ffd185d4b6d1a Signed-off-by: Michal Gajdos <[email protected]>
1 parent 68777c9 commit ceb94a1

File tree

11 files changed

+248
-210
lines changed

11 files changed

+248
-210
lines changed

docs/src/main/docbook/migration.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,43 @@
5252
xml:id="migration">
5353
<title>Migration Guide</title>
5454

55+
<section xml:id="mig-2.18">
56+
<title>Migrating from Jersey 2.17 to 2.18</title>
57+
<section xml:id="mig-2.18-highlights">
58+
<title>Release 2.18 Highlights</title>
59+
60+
<section>
61+
<title>Updated to MOXy 2.6</title>
62+
<para>
63+
Jersey has updated version of MOXy (XML/JSON provider) to version 2.6. Among some bug fixes there are other
64+
notable changes (some of them breaking) that you should be aware of:
65+
66+
<itemizedlist>
67+
<listitem>
68+
<para>
69+
<link xlink:href='https://wiki.eclipse.org/EclipseLink/DesignDocs/459464'>Redesign of type property in JSON processing</link> -
70+
Special handling of JSON <literal>type</literal> property is deprecated. If there is need to
71+
identify type of JSON object - due to missing root element or some special inheritance
72+
requirements, it is necessary to specify fully qualified type property with
73+
<literal>http://www.w3.org/2001/XMLSchema-instance</literal> namespace.
74+
</para>
75+
</listitem>
76+
<listitem>
77+
<para>
78+
<link xlink:href='https://bugs.eclipse.org/bugs/attachment.cgi?id=241506'>Bean Validation in MOXy</link>
79+
</para>
80+
</listitem>
81+
<listitem>
82+
<para>
83+
<link xlink:href='https://wiki.eclipse.org/EclipseLink/DesignDocs/405161'>MOXy support for for Java API for JSON Processing (JSR-353)</link>
84+
</para>
85+
</listitem>
86+
</itemizedlist>
87+
</para>
88+
</section>
89+
</section>
90+
</section>
91+
5592
<section xml:id="mig-2.17">
5693
<title>Migrating from Jersey 2.16 to 2.17</title>
5794
<section xml:id="mig-2.17-highlights">

examples/bean-validation-webapp/src/test/java/org/glassfish/jersey/examples/beanvalidation/webapp/ContactCardTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@
5555

5656
import org.glassfish.jersey.client.ClientConfig;
5757
import org.glassfish.jersey.examples.beanvalidation.webapp.domain.ContactCard;
58+
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
5859
import org.glassfish.jersey.moxy.json.MoxyJsonFeature;
5960
import org.glassfish.jersey.server.ServerProperties;
6061
import org.glassfish.jersey.server.validation.ValidationError;
6162
import org.glassfish.jersey.test.JerseyTest;
6263
import org.glassfish.jersey.test.TestProperties;
6364
import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
6465

66+
import org.eclipse.persistence.jaxb.BeanValidationMode;
67+
import org.eclipse.persistence.jaxb.MarshallerProperties;
6568
import org.junit.Test;
6669
import static org.junit.Assert.assertEquals;
6770
import static org.junit.Assert.assertNotNull;
@@ -100,6 +103,10 @@ protected void configureClient(final ClientConfig config) {
100103
super.configureClient(config);
101104

102105
config.register(MoxyJsonFeature.class);
106+
// Turn off BV otherwise the entities on client would be validated as well.
107+
config.register(new MoxyJsonConfig()
108+
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE)
109+
.resolver());
103110
}
104111

105112
@Override
@@ -186,7 +193,7 @@ private Set<String> getValidationMessageTemplates(final Response response) {
186193
}
187194

188195
private Set<String> getValidationMessageTemplates(final List<ValidationError> errors) {
189-
final Set<String> templates = new HashSet<String>();
196+
final Set<String> templates = new HashSet<>();
190197
for (final ValidationError error : errors) {
191198
templates.add(error.getMessageTemplate());
192199
}

media/moxy/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
<configuration>
8080
<instructions>
8181
<Export-Package>org.glassfish.jersey.moxy.*</Export-Package>
82-
<Import-Package>
83-
org.eclipse.persistence.jaxb.rs,
84-
*
85-
</Import-Package>
8682
</instructions>
8783
<unpackBundle>true</unpackBundle>
8884
</configuration>
@@ -122,10 +118,6 @@
122118
<groupId>org.eclipse.persistence</groupId>
123119
<artifactId>org.eclipse.persistence.moxy</artifactId>
124120
</dependency>
125-
<dependency>
126-
<groupId>org.eclipse.persistence</groupId>
127-
<artifactId>org.eclipse.persistence.antlr</artifactId>
128-
</dependency>
129121

130122
<dependency>
131123
<groupId>junit</groupId>

media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider.java

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@
4141

4242
import java.lang.annotation.Annotation;
4343
import java.lang.reflect.Field;
44-
import java.lang.reflect.GenericArrayType;
4544
import java.lang.reflect.Modifier;
46-
import java.lang.reflect.ParameterizedType;
4745
import java.lang.reflect.Type;
48-
import java.lang.reflect.WildcardType;
4946
import java.security.AccessController;
5047
import java.util.Map;
5148
import java.util.Set;
@@ -58,7 +55,6 @@
5855
import javax.ws.rs.ext.Providers;
5956

6057
import javax.inject.Singleton;
61-
import javax.xml.bind.JAXBElement;
6258
import javax.xml.bind.JAXBException;
6359
import javax.xml.bind.Marshaller;
6460
import javax.xml.bind.PropertyException;
@@ -99,7 +95,7 @@ private static Set<String> getPropertyNames(final Class<?> propertiesClass) {
9995
&& Modifier.isStatic(field.getModifiers())) {
10096
try {
10197
propertyNames.add((String) field.get(null));
102-
} catch (IllegalAccessException e) {
98+
} catch (final IllegalAccessException e) {
10399
// NOOP.
104100
}
105101
}
@@ -169,8 +165,9 @@ private void initializeMarshaller(final Marshaller marshaller) throws PropertyEx
169165
}
170166

171167
private Map<String, Object> getProperties(final boolean forMarshaller) {
172-
final Map<String, Object> properties = Maps.newHashMap(
173-
forMarshaller ? getGlobalConfig().getMarshallerProperties() : getGlobalConfig().getUnmarshallerProperties());
168+
final Map<String, Object> properties = Maps.newHashMap(forMarshaller
169+
? getGlobalConfig().getMarshallerProperties()
170+
: getGlobalConfig().getUnmarshallerProperties());
174171

175172
final ContextResolver<MoxyJsonConfig> contextResolver =
176173
providers.getContextResolver(MoxyJsonConfig.class, MediaType.APPLICATION_JSON_TYPE);
@@ -187,15 +184,21 @@ private Map<String, Object> getProperties(final boolean forMarshaller) {
187184
}
188185

189186
@Override
190-
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
191-
return !isPrimitiveType(type) && !Map.class.isAssignableFrom(type) && super.isReadable(type, genericType, annotations,
192-
mediaType);
187+
public boolean isReadable(final Class<?> type,
188+
final Type genericType,
189+
final Annotation[] annotations,
190+
final MediaType mediaType) {
191+
return !isPrimitiveType(type)
192+
&& super.isReadable(type, genericType, annotations, mediaType);
193193
}
194194

195195
@Override
196-
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
197-
return !isPrimitiveType(type) && !Map.class.isAssignableFrom(type) && super.isWriteable(type, genericType, annotations,
198-
mediaType);
196+
public boolean isWriteable(final Class<?> type,
197+
final Type genericType,
198+
final Annotation[] annotations,
199+
final MediaType mediaType) {
200+
return !isPrimitiveType(type)
201+
&& super.isWriteable(type, genericType, annotations, mediaType);
199202
}
200203

201204
private boolean isPrimitiveType(final Class<?> type) {
@@ -209,45 +212,4 @@ private boolean isPrimitiveType(final Class<?> type) {
209212
|| CoreClassConstants.PBOOLEAN == type || CoreClassConstants.BOOLEAN == type
210213
|| CoreClassConstants.PBYTE == type || CoreClassConstants.BYTE == type;
211214
}
212-
213-
@Override
214-
protected Class<?> getDomainClass(Type genericType) {
215-
if (null == genericType) {
216-
return Object.class;
217-
}
218-
if (genericType instanceof Class && genericType != JAXBElement.class) {
219-
Class<?> clazz = (Class<?>) genericType;
220-
if (clazz.isArray()) {
221-
return getDomainClass(clazz.getComponentType());
222-
}
223-
return clazz;
224-
} else if (genericType instanceof ParameterizedType) {
225-
Type type = ((ParameterizedType) genericType).getActualTypeArguments()[0];
226-
if (type instanceof ParameterizedType) {
227-
Type rawType = ((ParameterizedType) type).getRawType();
228-
if (rawType == JAXBElement.class) {
229-
return getDomainClass(type);
230-
} else if (rawType instanceof Class) {
231-
return (Class<?>) rawType;
232-
}
233-
} else if (type instanceof WildcardType) {
234-
Type[] upperTypes = ((WildcardType) type).getUpperBounds();
235-
if (upperTypes.length > 0) {
236-
Type upperType = upperTypes[0];
237-
if (upperType instanceof Class) {
238-
return (Class<?>) upperType;
239-
}
240-
}
241-
} else if (JAXBElement.class == type) {
242-
return Object.class;
243-
}
244-
return (Class<?>) type;
245-
} else if (genericType instanceof GenericArrayType) {
246-
GenericArrayType genericArrayType = (GenericArrayType) genericType;
247-
return getDomainClass(genericArrayType.getGenericComponentType());
248-
} else {
249-
return Object.class;
250-
}
251-
}
252-
253215
}

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,12 +1254,6 @@
12541254
<version>${moxy.version}</version>
12551255
</dependency>
12561256

1257-
<dependency>
1258-
<groupId>org.eclipse.persistence</groupId>
1259-
<artifactId>org.eclipse.persistence.antlr</artifactId>
1260-
<version>${moxy.version}</version>
1261-
</dependency>
1262-
12631257
<dependency>
12641258
<groupId>javax.persistence</groupId>
12651259
<artifactId>persistence-api</artifactId>
@@ -1618,7 +1612,7 @@
16181612
<jstl.version>1.2</jstl.version>
16191613
<jta.api.version>1.2</jta.api.version>
16201614
<mimepull.version>1.9.5</mimepull.version>
1621-
<moxy.version>2.5.0</moxy.version>
1615+
<moxy.version>2.6.0</moxy.version>
16221616
<mustache.version>0.8.17</mustache.version>
16231617
<osgi.version>4.2.0</osgi.version>
16241618
<pax.exam.version>3.3.0</pax.exam.version>

0 commit comments

Comments
 (0)