Juan Hernandez has uploaded a new change for review. Change subject: restapi: Add support for JAXB annotions in JSON ......................................................................
restapi: Add support for JAXB annotions in JSON The default JSON provider included with RESTEasy 2.x doesn't take into account the JAXB annotations, in particular it doesn't take into account the annotations that specify the names of elements and this generates inconsistencies in the names used in the XML representation and in the JSON representation. This problem has been fixed in RESTEasy 3.x but we can't use that version because it isn't included with JBoss AS 7. In order to solve the problem this patch adds a new JSON provider that takes into account the JAXB annotations. This provider replaces the builtin one. Change-Id: Ica39bbedd427dbf2f298b1292fe9a14f3825d6e5 Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- M backend/manager/modules/restapi/jaxrs/pom.xml A backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/json/JsonJAXBAnnotationAwareProvider.java M backend/manager/modules/restapi/webapp/src/main/resources/META-INF/MANIFEST.MF M backend/manager/modules/restapi/webapp/src/main/webapp/WEB-INF/web.xml M pom.xml 5 files changed, 46 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/20093/1 diff --git a/backend/manager/modules/restapi/jaxrs/pom.xml b/backend/manager/modules/restapi/jaxrs/pom.xml index a5acf5f..8b72ce8 100644 --- a/backend/manager/modules/restapi/jaxrs/pom.xml +++ b/backend/manager/modules/restapi/jaxrs/pom.xml @@ -52,6 +52,12 @@ </dependency> <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-jaxrs</artifactId> + <version>${jackson-jaxrs.version}</version> + </dependency> + + <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>1.8</version> diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/json/JsonJAXBAnnotationAwareProvider.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/json/JsonJAXBAnnotationAwareProvider.java new file mode 100644 index 0000000..459802e --- /dev/null +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/json/JsonJAXBAnnotationAwareProvider.java @@ -0,0 +1,30 @@ +package org.ovirt.engine.api.restapi.json; + +import org.codehaus.jackson.jaxrs.Annotations; +import org.codehaus.jackson.jaxrs.JacksonJsonProvider; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.ext.Provider; + +/** + * Extend the Jackson provider to support JAXB annotations. This support is already part of Jackson, but the JSON + * provider included in RESTEasy 2.x doesn't enable it. This has been fixed in RESTEasy 3.x, but we can't use that + * version of RESTEasy with JBoss AS 7. This provider must be explicitly loaded in the {@code web.xml} file of the + * application, as follows: + * + * <pre> + * <context-param> + * <param-name>resteasy.providers</param-name> + * <param-value>org.ovirt.engine.api.restapi.json.JsonJAXBAnnotationAwareProvider</param-value> + * </context-param> + * </pre> + */ +@Provider +@Consumes({"application/json"}) +@Produces({"application/json"}) +public class JsonJAXBAnnotationAwareProvider extends JacksonJsonProvider { + public JsonJAXBAnnotationAwareProvider() { + super(Annotations.JAXB); + } +} diff --git a/backend/manager/modules/restapi/webapp/src/main/resources/META-INF/MANIFEST.MF b/backend/manager/modules/restapi/webapp/src/main/resources/META-INF/MANIFEST.MF index 24d1ddb..401c183 100644 --- a/backend/manager/modules/restapi/webapp/src/main/resources/META-INF/MANIFEST.MF +++ b/backend/manager/modules/restapi/webapp/src/main/resources/META-INF/MANIFEST.MF @@ -1,2 +1,3 @@ Manifest-Version: 1.0 -Dependencies: org.yaml.snakeyaml +Dependencies: org.codehaus.jackson.jackson-jaxrs, + org.yaml.snakeyaml diff --git a/backend/manager/modules/restapi/webapp/src/main/webapp/WEB-INF/web.xml b/backend/manager/modules/restapi/webapp/src/main/webapp/WEB-INF/web.xml index eade16d..eb9d6d9 100644 --- a/backend/manager/modules/restapi/webapp/src/main/webapp/WEB-INF/web.xml +++ b/backend/manager/modules/restapi/webapp/src/main/webapp/WEB-INF/web.xml @@ -12,6 +12,13 @@ <param-value>false</param-value> </context-param> + <!-- Register the JSON provider that is aware of JAXB annotations (this is needed because the provider included in + RESTEasy 2.x doesn't take them into account, that has been fixed in RESTEasy 3.x): --> + <context-param> + <param-name>resteasy.providers</param-name> + <param-value>org.ovirt.engine.api.restapi.json.JsonJAXBAnnotationAwareProvider</param-value> + </context-param> + <!-- confidentiality --> <security-constraint> <web-resource-collection> diff --git a/pom.xml b/pom.xml index 1982d93..9124a4a 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ <hibernate-validator.version>4.0.2.GA</hibernate-validator.version> <jackson-core-asl.version>1.9.4</jackson-core-asl.version> <jackson-mapper-asl.version>1.9.4</jackson-mapper-asl.version> + <jackson-jaxrs.version>1.9.4</jackson-jaxrs.version> <commons-configuration.version>1.6</commons-configuration.version> <commons-jxpath.version>1.3</commons-jxpath.version> <jaxb-impl.version>2.2</jaxb-impl.version> -- To view, visit http://gerrit.ovirt.org/20093 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ica39bbedd427dbf2f298b1292fe9a14f3825d6e5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches