Skip to content

Commit c164c6e

Browse files
dpbevincowtowncoder
authored andcommitted
Fixes #182. Negative numbers serialized with quotes.
1 parent d692916 commit c164c6e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private Feature(boolean defaultState) {
172172

173173
protected final static long MIN_INT_AS_LONG = (long) Integer.MIN_VALUE;
174174
protected final static long MAX_INT_AS_LONG = (long) Integer.MAX_VALUE;
175-
protected final static Pattern PLAIN_NUMBER_P = Pattern.compile("[0-9]*(\\.[0-9]*)?");
175+
protected final static Pattern PLAIN_NUMBER_P = Pattern.compile("-?[0-9]*(\\.[0-9]*)?");
176176
protected final static String TAG_BINARY = Tag.BINARY.toString();
177177

178178
// for field names, leave out quotes

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/GeneratorWithMinimizeTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ public void testQuoteNumberStoredAsString() throws Exception
186186

187187
assertEquals("---\n" +
188188
"key: 2.0.1.2.3", yaml);
189+
190+
content.clear();
191+
content.put("key", "-60");
192+
yaml = mapper.writeValueAsString(content).trim();
193+
194+
assertEquals("---\n" +
195+
"key: \"-60\"", yaml);
189196
}
190197

191198
public void testNonQuoteNumberStoredAsString() throws Exception

0 commit comments

Comments
 (0)