Skip to content

Commit

Permalink
Don't attempt to serialize Iterables and don't special case serializa…
Browse files Browse the repository at this point in the history
…tion for Path objects, fixes broken Android release. (#495)
  • Loading branch information
bretthoerner authored Aug 22, 2017
1 parent 2d4743f commit f9f04c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Version 1.5.1
-------------

-
- Don't attempt to serialize Iterables and don't special case serialization for Path objects, fixes broken Android release.

Version 1.5.0
-------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;

/**
Expand Down Expand Up @@ -72,24 +72,6 @@ private void writeObject(Object value, int recursionLevel) throws IOException {
generator.writeStartArray();
writeArray(value, recursionLevel);
generator.writeEndArray();
} else if (value instanceof Path) {
// Path is weird because it implements Iterable, and then the iterator returns
// more Paths, which are iterable... which would cause a stack overflow below.
generator.writeString(Util.trimString(value.toString(), maxLengthString));
} else if (value instanceof Iterable) {
generator.writeStartArray();
int i = 0;
for (Object subValue : (Iterable<?>) value) {
if (i >= maxLengthList) {
writeElided();
break;
}

writeObject(subValue, recursionLevel + 1);

i++;
}
generator.writeEndArray();
} else if (value instanceof Map) {
generator.writeStartObject();
int i = 0;
Expand All @@ -108,6 +90,20 @@ private void writeObject(Object value, int recursionLevel) throws IOException {
i++;
}
generator.writeEndObject();
} else if (value instanceof Collection) {
generator.writeStartArray();
int i = 0;
for (Object subValue : (Collection<?>) value) {
if (i >= maxLengthList) {
writeElided();
break;
}

writeObject(subValue, recursionLevel + 1);

i++;
}
generator.writeEndArray();
} else if (value instanceof String) {
generator.writeString(Util.trimString((String) value, maxLengthString));
} else {
Expand Down

0 comments on commit f9f04c2

Please sign in to comment.