← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9184: updated to jackson 2.1.1, updated several getters to check for null (jackson 2.1.x is a bit more ...

 

------------------------------------------------------------
revno: 9184
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-06 12:06:40 +0300
message:
  updated to jackson 2.1.1, updated several getters to check for null (jackson 2.1.x is a bit more strict, consider meta-data import wip)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java
  dhis-2/pom.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2012-10-18 13:04:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2012-12-06 09:06:40 +0000
@@ -42,12 +42,15 @@
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
 
-import java.util.*;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
 /**
  * @author Abyot Aselefew
  */
-@JacksonXmlRootElement( localName = "categoryOptionCombo", namespace = Dxf2Namespace.NAMESPACE )
+@JacksonXmlRootElement(localName = "categoryOptionCombo", namespace = Dxf2Namespace.NAMESPACE)
 public class DataElementCategoryOptionCombo
     extends BaseNameableObject
 {
@@ -76,7 +79,7 @@
     // -------------------------------------------------------------------------
 
     private transient String name;
-    
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -159,7 +162,12 @@
 
         while ( iterator.hasNext() )
         {
-            builder.append( iterator.next().toString() );
+            DataElementCategoryOption dataElementCategoryOption = iterator.next();
+
+            if ( dataElementCategoryOption != null )
+            {
+                builder.append( dataElementCategoryOption.toString() );
+            }
 
             if ( iterator.hasNext() )
             {
@@ -275,18 +283,29 @@
         {
             return name;
         }
-        
+
         StringBuilder name = new StringBuilder();
 
         if ( categoryOptions != null && categoryOptions.size() > 0 )
         {
+            name.append( "(" );
+
             Iterator<DataElementCategoryOption> iterator = categoryOptions.iterator();
+            DataElementCategoryOption dataElementCategoryOption = iterator.next();
 
-            name.append( "(" ).append( iterator.next().getDisplayName() );
+            if ( dataElementCategoryOption != null )
+            {
+                name.append( dataElementCategoryOption.getDisplayName() );
+            }
 
             while ( iterator.hasNext() )
             {
-                name.append( ", " ).append( iterator.next().getDisplayName() );
+                DataElementCategoryOption categoryOption = iterator.next();
+
+                if ( categoryOption != null )
+                {
+                    name.append( ", " ).append( categoryOption.getDisplayName() );
+                }
             }
 
             name.append( ")" );
@@ -316,7 +335,7 @@
 
     @JsonProperty
     @JsonSerialize( contentAs = BaseIdentifiableObject.class )
-    @JsonView( {DetailedView.class, ExportView.class} )
+    @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public DataElementCategoryCombo getCategoryCombo()
     {
@@ -329,10 +348,10 @@
     }
 
     @JsonProperty
-    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
-    @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlElementWrapper( localName = "categoryOptions", namespace = Dxf2Namespace.NAMESPACE )
-    @JacksonXmlProperty( localName = "categoryOption", namespace = Dxf2Namespace.NAMESPACE )
+    @JsonSerialize(contentAs = BaseIdentifiableObject.class)
+    @JsonView({ DetailedView.class, ExportView.class })
+    @JacksonXmlElementWrapper(localName = "categoryOptions", namespace = Dxf2Namespace.NAMESPACE)
+    @JacksonXmlProperty(localName = "categoryOption", namespace = Dxf2Namespace.NAMESPACE)
     public Set<DataElementCategoryOption> getCategoryOptions()
     {
         return categoryOptions;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java	2012-11-29 16:21:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java	2012-12-06 09:06:40 +0000
@@ -72,7 +72,7 @@
     @Override
     public int hashCode()
     {
-        return name.hashCode();
+        return name == null ? 0 : name.hashCode();
     }
 
     @Override

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java	2012-11-29 16:21:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java	2012-12-06 09:06:40 +0000
@@ -47,7 +47,7 @@
 /**
  * @author Jan Henrik Overland
  */
-@JacksonXmlRootElement( localName = "mapLegendSet", namespace = Dxf2Namespace.NAMESPACE )
+@JacksonXmlRootElement(localName = "mapLegendSet", namespace = Dxf2Namespace.NAMESPACE)
 public class MapLegendSet
     extends BaseIdentifiableObject
 {
@@ -75,7 +75,7 @@
     @Override
     public int hashCode()
     {
-        return name.hashCode();
+        return name == null ? 0 : name.hashCode();
     }
 
     @Override
@@ -115,8 +115,8 @@
     // -------------------------------------------------------------------------
 
     @JsonProperty
-    @JsonView( { DetailedView.class, ExportView.class } )
-    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
+    @JsonView({ DetailedView.class, ExportView.class })
+    @JacksonXmlProperty(namespace = Dxf2Namespace.NAMESPACE)
     public String getSymbolizer()
     {
         return symbolizer;
@@ -129,9 +129,9 @@
 
     @JsonProperty
     // @JsonDeserialize( using = JacksonMapLegendsDeserializer.class )
-    @JsonView( { DetailedView.class, ExportView.class } )
-    @JacksonXmlElementWrapper( localName = "mapLegends", namespace = Dxf2Namespace.NAMESPACE )
-    @JacksonXmlProperty( localName = "mapLegend", namespace = Dxf2Namespace.NAMESPACE )
+    @JsonView({ DetailedView.class, ExportView.class })
+    @JacksonXmlElementWrapper(localName = "mapLegends", namespace = Dxf2Namespace.NAMESPACE)
+    @JacksonXmlProperty(localName = "mapLegend", namespace = Dxf2Namespace.NAMESPACE)
     public Set<MapLegend> getMapLegends()
     {
         return mapLegends;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2012-12-05 07:32:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2012-12-06 09:06:40 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -544,9 +545,9 @@
     {
         StringBuilder builder = new StringBuilder();
 
-        List<OrganisationUnit> anchestors = getAncestors();
+        List<OrganisationUnit> ancestors = getAncestors();
 
-        for ( OrganisationUnit unit : anchestors )
+        for ( OrganisationUnit unit : ancestors )
         {
             builder.append( "/" ).append( unit.getUid() );
         }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-08-22 12:45:25 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-12-06 09:06:40 +0000
@@ -187,7 +187,7 @@
 
     private <T> Importer<T> findImporterClass( List<?> clazzes )
     {
-        if ( !clazzes.isEmpty() )
+        if ( !clazzes.isEmpty() && clazzes.get( 0 ) != null )
         {
             return findImporterClass( clazzes.get( 0 ).getClass() );
         }
@@ -197,11 +197,14 @@
 
     private <T> Importer<T> findImporterClass( Class<?> clazz )
     {
-        for ( Importer<T> i : importerClasses )
+        if ( clazz != null )
         {
-            if ( i.canHandle( clazz ) )
+            for ( Importer<T> i : importerClasses )
             {
-                return i;
+                if ( i.canHandle( clazz ) )
+                {
+                    return i;
+                }
             }
         }
 
@@ -210,7 +213,7 @@
 
     private <T> ImportTypeSummary doImport( List<T> objects, ImportOptions importOptions )
     {
-        if ( !objects.isEmpty() )
+        if ( !objects.isEmpty() && objects.get( 0 ) != null )
         {
             Importer<T> importer = findImporterClass( objects );
 

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java	2012-07-30 10:56:25 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java	2012-12-06 09:06:40 +0000
@@ -29,6 +29,7 @@
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.MapperFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
@@ -58,7 +59,7 @@
 
     static
     {
-        ObjectMapper[] objectMappers = new ObjectMapper[] { jsonMapper, xmlMapper };
+        ObjectMapper[] objectMappers = new ObjectMapper[]{ jsonMapper, xmlMapper };
         // DateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" );
 
         for ( ObjectMapper objectMapper : objectMappers )
@@ -68,6 +69,12 @@
             objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
             objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false );
             objectMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false );
+            objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true );
+
+            objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+            objectMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
+            objectMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );
+
             objectMapper.disable( MapperFeature.AUTO_DETECT_FIELDS );
             objectMapper.disable( MapperFeature.AUTO_DETECT_CREATORS );
             objectMapper.disable( MapperFeature.AUTO_DETECT_GETTERS );
@@ -75,7 +82,7 @@
             objectMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS );
         }
 
-        jsonMapper.getJsonFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
+        jsonMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
         xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true );
 
         // register view classes

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2012-12-06 07:50:37 +0000
+++ dhis-2/pom.xml	2012-12-06 09:06:40 +0000
@@ -891,7 +891,7 @@
     <spring.version>3.1.3.RELEASE</spring.version>
     <spring.security.version>3.1.3.RELEASE</spring.security.version>
     <hibernate.version>4.1.8.Final</hibernate.version>
-    <jackson.version>2.0.5</jackson.version>
+    <jackson.version>2.1.1</jackson.version>
     <camel.version>2.10.2</camel.version>
     <slf4j.version>1.6.6</slf4j.version>
   </properties>