You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/10/26 15:07:09 UTC

[GitHub] bosschaert closed pull request #7: SLING-8053 - Fix Text Extension Serialization.

bosschaert closed pull request #7: SLING-8053 - Fix Text Extension Serialization.
URL: https://github.com/apache/sling-org-apache-sling-feature-io/pull/7
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java b/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java
index 19f6282..3533e68 100644
--- a/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java
+++ b/src/main/java/org/apache/sling/feature/io/json/JSONWriterBase.java
@@ -222,7 +222,11 @@ protected void writeExtensions(final JsonGenerator generator,
                 }
                 generator.write(key, struct);
             } else if ( ext.getType() == ExtensionType.TEXT ) {
-                generator.write(key, ext.getText());
+                generator.writeStartArray(key);
+                for(String line : ext.getText().split("\n")) {
+                    generator.write(line);
+                }
+                generator.writeEnd();
             } else {
                 generator.writeStartArray(key);
                 for(final Artifact artifact : ext.getArtifacts()) {
diff --git a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java
index 314925a..2389334 100644
--- a/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java
+++ b/src/test/java/org/apache/sling/feature/io/json/FeatureJSONWriterTest.java
@@ -17,10 +17,13 @@
 package org.apache.sling.feature.io.json;
 
 import org.apache.sling.feature.Feature;
+import org.junit.Assert;
 import org.junit.Test;
 
-import java.io.StringReader;
-import java.io.StringWriter;
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import java.io.*;
 import java.util.Arrays;
 
 import static org.junit.Assert.assertEquals;
@@ -86,4 +89,18 @@
         assertEquals(f.getInclude().getId(), rf.getInclude().getId());
     }
 
+    @Test public void testRepoInitWrite() throws Exception {
+        final Feature f = U.readFeature("repoinit2");
+        try ( final StringWriter writer = new StringWriter() ) {
+            FeatureJSONWriter.write(writer, f);
+            final JsonObject refJson = Json.createReader(
+                    new InputStreamReader(U.class.getResourceAsStream("/features/repoinit2.json"))
+                ).readObject();
+            final JsonObject resultJson = Json.createReader(new StringReader(writer.toString())).readObject();
+
+            JsonArray refJsonArray = refJson.getJsonArray("repoinit:TEXT|false");
+            JsonArray resultJsonArray = resultJson.getJsonArray("repoinit:TEXT|false");
+            Assert.assertEquals(refJsonArray, resultJsonArray);
+        }
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services