[jackson-jaxrs-providers] 37/162: Test case showing that JSON serialization without FLUSH_AFTER_WRITE_VALUE fails.

Timo Aaltonen tjaalton at moszumanska.debian.org
Mon Sep 8 22:16:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

tjaalton pushed a commit to branch master
in repository jackson-jaxrs-providers.

commit dafb5da4fe9ee43d3b2a79153e8e27f872f5eeda
Author: Steven Schlansker <steven at likeness.com>
Date:   Fri Apr 12 12:04:20 2013 -0700

    Test case showing that JSON serialization without FLUSH_AFTER_WRITE_VALUE fails.
---
 .../jaxrs/json/TestSerializeWithoutAutoflush.java  | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/json/src/test/java/com/fasterxml/jackson/jaxrs/json/TestSerializeWithoutAutoflush.java b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/TestSerializeWithoutAutoflush.java
new file mode 100644
index 0000000..503a52d
--- /dev/null
+++ b/json/src/test/java/com/fasterxml/jackson/jaxrs/json/TestSerializeWithoutAutoflush.java
@@ -0,0 +1,52 @@
+package com.fasterxml.jackson.jaxrs.json;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+/**
+ * Unit test to check that ProviderBase always writes its content, even if flush-after-write is off.
+ */
+public class TestSerializeWithoutAutoflush extends JaxrsTestBase
+{
+    static class Simple {
+        protected List<String> list;
+
+        public List<String> getList( ) { return list; }
+        public void setList(List<String> l) { list = l; }
+    }
+
+    public void testCanSerialize() throws IOException
+    {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);
+        mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
+
+        JacksonJsonProvider provider = new JacksonJsonProvider(mapper);
+
+        // construct test object
+        List<String> l = new ArrayList<String>();
+        l.add("foo");
+        l.add("bar");
+
+        Simple s = new Simple();
+        s.setList(l);
+
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+
+        provider.writeTo(s, Simple.class, Simple.class, new Annotation[0],
+                MediaType.APPLICATION_JSON_TYPE, null, stream);
+
+        Simple result = mapper.readValue(stream.toByteArray(), Simple.class);
+        assertNotNull(result.list);
+        assertEquals(2, result.list.size());
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-jaxrs-providers.git



More information about the pkg-java-commits mailing list