Revision: 5164
          http://sourceforge.net/p/jump-pilot/code/5164
Author:   edso
Date:     2016-11-06 12:01:19 +0000 (Sun, 06 Nov 2016)
Log Message:
-----------
write NULL values for first feature _only_ to make sure that the attribute 
order stays the same when round tripping (load/save/load)

Modified Paths:
--------------
    
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java

Modified: 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
      2016-11-06 10:57:52 UTC (rev 5163)
+++ 
core/trunk/src/com/vividsolutions/jump/io/geojson/GeoJSONFeatureCollectionWrapper.java
      2016-11-06 12:01:19 UTC (rev 5164)
@@ -252,12 +252,12 @@
       if (TaskMonitorUtil.isCancelRequested(monitor))
         break;
 
-      if (first)
-        first = false;
-      else
+      // write separator after first dataset
+      if (!first)
         out.write(",\n");
 
-      String featureJson = toJSONString(feature);
+      // only first dataset writes NULL values to keep attribute order
+      String featureJson = toJSONString(feature, first);
       out.write(featureJson);
 
       long now = Timer.milliSecondsSince(0);
@@ -267,14 +267,21 @@
         milliSeconds = now;
         TaskMonitorUtil.report(monitor, count, size(), "");
       }
-
+      
+      // unset first marker
+      if (first)
+        first = false;
     }
     out.write("\n]");
 
     out.write("\n\n}");
   }
 
-  public static String toJSONString(Feature feature) {
+  private static String toJSONString(Feature feature) {
+    return toJSONString(feature, false);
+  }
+
+  private static String toJSONString(Feature feature, boolean saveNullValues) {
     String propertiesJson = null, geometryJson = null;
     FeatureSchema schema = feature.getSchema();
 
@@ -292,7 +299,7 @@
       // attrib to json
       else {
         // we do NOT save null values to minimize the file size
-        if (value == null)
+        if (!saveNullValues && value == null)
           continue;
 
         // Date objects should be saved quoted in String representation


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to