| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | import com.fasterxml.jackson.core.JsonParser; | |
| 11 | 11 | import com.fasterxml.jackson.core.JsonToken; | |
| 12 | 12 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 13 | + import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 13 | 14 | import com.github.dockerjava.api.async.ResultCallback; | |
| 14 | 15 | ||
| 15 | 16 | /** | |
@@ -41,8 +42,12 @@ public void processResponseStream(InputStream response, ResultCallback<T> result | |||
| 41 | 42 | JsonToken nextToken = jp.nextToken(); | |
| 42 | 43 | while (!closed && nextToken != null && nextToken != JsonToken.END_OBJECT) { | |
| 43 | 44 | try { | |
| 44 | - T next = OBJECT_MAPPER.readValue(jp, clazz); | ||
| 45 | - resultCallback.onNext(next); | ||
| 45 | + ObjectNode objectNode = OBJECT_MAPPER.readTree(jp); | ||
| 46 | + // exclude empty item serialization into class #461 | ||
| 47 | + if (!(objectNode.size() == 0)) { | ||
| 48 | + T next = OBJECT_MAPPER.treeToValue(objectNode, clazz); | ||
| 49 | + resultCallback.onNext(next); | ||
| 50 | + } | ||
| 46 | 51 | } catch (Exception e) { | |
| 47 | 52 | resultCallback.onError(e); | |
| 48 | 53 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,65 @@ | |||
| 1 | + /* | ||
| 2 | + * Created on 16.02.2016 | ||
| 3 | + */ | ||
| 4 | + package com.github.dockerjava.core.async; | ||
| 5 | + | ||
| 6 | + import static org.testng.Assert.assertFalse; | ||
| 7 | + | ||
| 8 | + import java.io.ByteArrayInputStream; | ||
| 9 | + import java.io.Closeable; | ||
| 10 | + import java.io.IOException; | ||
| 11 | + import java.io.InputStream; | ||
| 12 | + import java.util.ArrayList; | ||
| 13 | + import java.util.List; | ||
| 14 | + | ||
| 15 | + import org.testng.annotations.Test; | ||
| 16 | + | ||
| 17 | + import com.github.dockerjava.api.async.ResultCallback; | ||
| 18 | + import com.github.dockerjava.api.model.PullResponseItem; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * | ||
| 23 | + * @author Marcus Linke | ||
| 24 | + * | ||
| 25 | + */ | ||
| 26 | + public class JsonStreamProcessorTest { | ||
| 27 | + | ||
| 28 | + @Test | ||
| 29 | + public void processEmptyJson() throws Exception { | ||
| 30 | + | ||
| 31 | + InputStream response = new ByteArrayInputStream("{}".getBytes()); | ||
| 32 | + | ||
| 33 | + JsonStreamProcessor<PullResponseItem> jsonStreamProcessor = new JsonStreamProcessor<PullResponseItem>(PullResponseItem.class); | ||
| 34 | + | ||
| 35 | + final List<Boolean> completed = new ArrayList<Boolean>(); | ||
| 36 | + | ||
| 37 | + jsonStreamProcessor.processResponseStream(response, new ResultCallback<PullResponseItem>() { | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void close() throws IOException { | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @Override | ||
| 44 | + public void onStart(Closeable closeable) { | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void onNext(PullResponseItem object) { | ||
| 49 | + assertFalse(true, "onNext called for empty json"); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void onError(Throwable throwable) { | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void onComplete() { | ||
| 58 | + completed.add(true); | ||
| 59 | + } | ||
| 60 | + }); | ||
| 61 | + | ||
| 62 | + assertFalse(completed.isEmpty(), "Stream processing not completed"); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments