Skip to content

Commit 14da256

Browse files
dpbevincowtowncoder
authored andcommitted
Fixes #182. Negative numbers serialized with quotes.
1 parent 580159d commit 14da256

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
@@ -168,7 +168,7 @@ private Feature(boolean defaultState) {
168168

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

174174
/* As per <a href="https://yaml.org/type/bool.html">YAML Spec</a> there are a few

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

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

134134
assertEquals("---\n" +
135135
"key: 2.0.1.2.3", yaml);
136+
137+
content.clear();
138+
content.put("key", "-60");
139+
yaml = mapper.writeValueAsString(content).trim();
140+
141+
assertEquals("---\n" +
142+
"key: \"-60\"", yaml);
136143
}
137144

138145
public void testNonQuoteNumberStoredAsString() throws Exception

0 commit comments

Comments
 (0)