[
https://issues.apache.org/jira/browse/GROOVY-8794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16616393#comment-16616393
]
ASF GitHub Bot commented on GROOVY-8794:
----------------------------------------
Github user jwagenleitner commented on a diff in the pull request:
https://github.com/apache/groovy/pull/797#discussion_r217889473
--- Diff:
subprojects/groovy-yaml/src/main/java/groovy/yaml/YamlBuilder.java ---
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 groovy.yaml;
+
+import groovy.json.JsonBuilder;
+import groovy.lang.Closure;
+import groovy.lang.GroovyObjectSupport;
+import groovy.lang.Writable;
+import groovy.yaml.util.YamlConverter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A builder for creating YAML payloads.
+ *
+ * @since 2.5.3
+ */
+public class YamlBuilder extends GroovyObjectSupport implements Writable {
+ private JsonBuilder jsonBuilder;
+
+ public YamlBuilder() {
+ this.jsonBuilder = new JsonBuilder();
+ }
+
+ public Object getContent() {
+ return jsonBuilder.getContent();
+ }
+
+ /**
+ * Named arguments can be passed to the YAML builder instance to
create a root YAML object
+ * <p>
+ * Example:
+ * <pre><code class="groovyTestCase">
+ * def yaml = new groovy.yaml.YamlBuilder()
+ * yaml name: "Guillaume", age: 33
+ *
+ * assert yaml.toString() == '{"name":"Guillaume","age":33}'
--- End diff --
Looks like most of the `YamlBuilder#toString` javadoc examples in this
class shows `json` instead of `yaml` output.
> Add groovy-yaml subproject to support parsing and building yaml
> ---------------------------------------------------------------
>
> Key: GROOVY-8794
> URL: https://issues.apache.org/jira/browse/GROOVY-8794
> Project: Groovy
> Issue Type: New Feature
> Reporter: Daniel Sun
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 2.5.3
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)