Skip to content

Commit

Permalink
Support negative floating point exponent values in JSONSerializer.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pivot/branches/1.5.x@1036009 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Gregory K. Brown committed Nov 17, 2010
1 parent 6c5deca commit d9a2171
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/org/apache/pivot/json/JSONSerializer.java
Expand Up @@ -382,7 +382,7 @@ private Object readNumber(Reader reader, Type type)
} }


while (c != -1 && (Character.isDigit(c) || c == '.' while (c != -1 && (Character.isDigit(c) || c == '.'
|| c == 'e' || c == 'E')) { || c == 'e' || c == 'E' || c == '-')) {
stringBuilder.append((char)c); stringBuilder.append((char)c);
integer &= !(c == '.'); integer &= !(c == '.');
c = reader.read(); c = reader.read();
Expand Down
6 changes: 6 additions & 0 deletions core/test/org/apache/pivot/json/test/JSONSerializerTest.java
Expand Up @@ -51,6 +51,12 @@ public void testInvalidNumbers() {
JSONSerializer.toString(Double.POSITIVE_INFINITY); JSONSerializer.toString(Double.POSITIVE_INFINITY);
} }


@Test
public void testE() throws SerializationException {
assertEquals(5000000, JSONSerializer.parseDouble("5.0E6"), 0);
assertEquals(0.000005, JSONSerializer.parseDouble("5.0E-6"), 0);
}

@Test @Test
public void testEquals() throws IOException, SerializationException { public void testEquals() throws IOException, SerializationException {
JSONSerializer jsonSerializer = new JSONSerializer(); JSONSerializer jsonSerializer = new JSONSerializer();
Expand Down

0 comments on commit d9a2171

Please sign in to comment.