Fix ID format for numbers over 999
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ea46f3..8537b54 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -7,6 +7,9 @@
</properties>
<body>
<release version="1.6-SNAPSHOT" date="in Mercurial" description="development">
+ <action dev="py4fun" type="fix" issue="38" due-to="gchpaco">
+ Fix ID format for numbers over 999 (2009-12-05)
+ </action>
<action dev="py4fun" type="fix" issue="29" due-to="grignaak">
Allow separate option in DumperOptions for long strings (2009-11-16)
</action>
diff --git a/src/main/java/org/yaml/snakeyaml/serializer/Serializer.java b/src/main/java/org/yaml/snakeyaml/serializer/Serializer.java
index 0cca9a0..c2c22d4 100644
--- a/src/main/java/org/yaml/snakeyaml/serializer/Serializer.java
+++ b/src/main/java/org/yaml/snakeyaml/serializer/Serializer.java
@@ -151,6 +151,7 @@
this.lastAnchorId++;
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumIntegerDigits(3);
+ format.setGroupingUsed(false);
String anchorId = format.format(this.lastAnchorId);
return "id" + anchorId;
}
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue38/Bean.java b/src/test/java/org/yaml/snakeyaml/issues/issue38/Bean.java
new file mode 100644
index 0000000..67c1384
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue38/Bean.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2008-2009 Andrey Somov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.yaml.snakeyaml.issues.issue38;
+
+public class Bean {
+ int value;
+
+ public Bean() {
+ }
+
+ public Bean(int value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return toString().equals(obj.toString());
+ }
+
+ @Override
+ public int hashCode() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Bean " + String.valueOf(value);
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/yaml/snakeyaml/issues/issue38/BigNumberIdTest.java b/src/test/java/org/yaml/snakeyaml/issues/issue38/BigNumberIdTest.java
new file mode 100644
index 0000000..afb72a9
--- /dev/null
+++ b/src/test/java/org/yaml/snakeyaml/issues/issue38/BigNumberIdTest.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2008-2009 Andrey Somov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.yaml.snakeyaml.issues.issue38;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * to test http://code.google.com/p/snakeyaml/issues/detail?id=38
+ */
+public class BigNumberIdTest extends TestCase {
+ @SuppressWarnings("unchecked")
+ public void testBigNumberFormat() throws IOException {
+ List<Bean> list = new ArrayList<Bean>(2000);
+ for (int i = 1; i < 1010; i++) {
+ Bean value = new Bean(i);
+ list.add(value);
+ list.add(value);
+ }
+ Yaml yaml = new Yaml();
+ String output = yaml.dump(list);
+ // System.out.println(output);
+ //
+ List<Bean> list2 = (List<Bean>) yaml.load(output);
+ for (Bean bean : list2) {
+ assertTrue(bean.getValue() > 0);
+ }
+ }
+}