[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/797 ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user danielsun1106 commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217901272 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to --- End diff -- OK. I will refine the docs according to your suggestions later. ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217901029 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to --- End diff -- I'd tweak the first sentence: Groovy has an optional `groovy-yaml` module which provides support ... (as before) ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user danielsun1106 commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217900520 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to +YAML serialisation and parsing are found in the `groovy.yaml` package. + +[[yaml_yamlslurper]] +== YamlSlurper + +`YamlSlurper` is a class that parses YAML text or reader content into Groovy data structures (objects) such as maps, lists and +primitive types like `Integer`, `Double`, `Boolean` and `String`. + +The class comes with a bunch of overloaded `parse` methods plus some special methods such as `parseText` +and others. For the next example we will use the `parseText` method. It parses a YAML `String` and recursively converts it to a +list or map of objects. The other `parse*` methods are similar in that they return a YAML `String` but for different parameter +types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +Notice the result is a plain map and can be handled like a normal Groovy object instance. `YamlSlurper` parses the +given YAML as defined by the http://yaml.org/spec/1.2/spec.html[YAML Ainât Markup Language (YAMLâ¢)]. + +In addition to maps `YamlSlurper` supports YAML arrays which are converted to lists. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +The YAML standard supports the following primitive data types: string, number, object, `true`, `false` and `null`. `YamlSlurper` +converts these YAML types into corresponding Groovy types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy --- End diff -- To be frank, I do not know how to use tags to write docs... If you could give me a hand, that would be great. ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user danielsun1106 commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217900457 --- Diff: build.gradle --- @@ -160,6 +160,8 @@ ext { spockVersion = '1.2-groovy-2.4-SNAPSHOT' // supports 3.0 antlr4Version = '4.7.1' jsr305Version = '3.0.2' +jacksondataformatyamlVersion = '2.9.6' +jacksondatabindVersion = '2.9.6' --- End diff -- I will move them later. ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217899766 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to +YAML serialisation and parsing are found in the `groovy.yaml` package. + +[[yaml_yamlslurper]] +== YamlSlurper + +`YamlSlurper` is a class that parses YAML text or reader content into Groovy data structures (objects) such as maps, lists and +primitive types like `Integer`, `Double`, `Boolean` and `String`. + +The class comes with a bunch of overloaded `parse` methods plus some special methods such as `parseText` +and others. For the next example we will use the `parseText` method. It parses a YAML `String` and recursively converts it to a +list or map of objects. The other `parse*` methods are similar in that they return a YAML `String` but for different parameter +types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +Notice the result is a plain map and can be handled like a normal Groovy object instance. `YamlSlurper` parses the +given YAML as defined by the http://yaml.org/spec/1.2/spec.html[YAML Ainât Markup Language (YAMLâ¢)]. + +In addition to maps `YamlSlurper` supports YAML arrays which are converted to lists. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +The YAML standard supports the following primitive data types: string, number, object, `true`, `false` and `null`. `YamlSlurper` +converts these YAML types into corresponding Groovy types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy --- End diff -- this is the whole file for a third time. Is this needed? ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217899761 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to +YAML serialisation and parsing are found in the `groovy.yaml` package. + +[[yaml_yamlslurper]] +== YamlSlurper + +`YamlSlurper` is a class that parses YAML text or reader content into Groovy data structures (objects) such as maps, lists and +primitive types like `Integer`, `Double`, `Boolean` and `String`. + +The class comes with a bunch of overloaded `parse` methods plus some special methods such as `parseText` +and others. For the next example we will use the `parseText` method. It parses a YAML `String` and recursively converts it to a +list or map of objects. The other `parse*` methods are similar in that they return a YAML `String` but for different parameter +types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +Notice the result is a plain map and can be handled like a normal Groovy object instance. `YamlSlurper` parses the +given YAML as defined by the http://yaml.org/spec/1.2/spec.html[YAML Ainât Markup Language (YAMLâ¢)]. + +In addition to maps `YamlSlurper` supports YAML arrays which are converted to lists. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy --- End diff -- you are bringing in the whole file again - you can use tags to bring in just part of it ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217899737 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to +YAML serialisation and parsing are found in the `groovy.yaml` package. + +[[yaml_yamlslurper]] +== YamlSlurper + +`YamlSlurper` is a class that parses YAML text or reader content into Groovy data structures (objects) such as maps, lists and +primitive types like `Integer`, `Double`, `Boolean` and `String`. + +The class comes with a bunch of overloaded `parse` methods plus some special methods such as `parseText` +and others. For the next example we will use the `parseText` method. It parses a YAML `String` and recursively converts it to a +list or map of objects. The other `parse*` methods are similar in that they return a YAML `String` but for different parameter +types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +Notice the result is a plain map and can be handled like a normal Groovy object instance. `YamlSlurper` parses the +given YAML as defined by the http://yaml.org/spec/1.2/spec.html[YAML Ainât Markup Language (YAMLâ¢)]. + +In addition to maps `YamlSlurper` supports YAML arrays which are converted to lists. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +The YAML standard supports the following primitive data types: string, number, object, `true`, `false` and `null`. `YamlSlurper` +converts these YAML types into corresponding Groovy types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy + + +As `YamlSlurper` is returning pure Groovy object instances without any special YAML classes in the back, its usage +is transparent. In fact, `YamlSlurper` results conform to GPath expressions. GPath is a powerful expression language +that is supported by multiple slurpers for different data formats (`XmlSlurper` for XML being one example). + +[NOTE] +For more details please have a look at the section on <>. + +The following table gives an overview of the YAML types and the corresponding Groovy data types: + +[cols="1,3" options="header"] +|=== +|YAML +|Groovy + +|string +|`java.lang.String` + +|number +|`java.lang.BigDecimal` or `java.lang.Integer` + +|object +|`java.util.LinkedHashMap` + +|array +|`java.util.ArrayList` + +|true +|`true` + +|false +|`false` + +|null +|`null` + +|date +|`java.util.Date` based on the `-MM-dd'T'HH:mm:ssZ` date format +|=== + +[NOTE] +Whenever a value in YAML is `null`, `YamlSlurper` supplements it with the Groovy `null` value. This is in contrast to other +YAML parsers that represent a `null` value with a library-provided singleton object. + +=== Builders + +Another way to create YAML from Groovy is to use `YamlBuilder`. The builder provide a +DSL which allows to formulate an object graph which is then converted to YAML. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlBuilderTest.groovy --- End diff -- I'd just bring in lines 24-50 ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217899707 --- Diff: build.gradle --- @@ -160,6 +160,8 @@ ext { spockVersion = '1.2-groovy-2.4-SNAPSHOT' // supports 3.0 antlr4Version = '4.7.1' jsr305Version = '3.0.2' +jacksondataformatyamlVersion = '2.9.6' +jacksondatabindVersion = '2.9.6' --- End diff -- I'd move these into the subproject too ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user paulk-asert commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217899699 --- Diff: subprojects/groovy-yaml/src/spec/doc/yaml-userguide.adoc --- @@ -0,0 +1,112 @@ +// + + 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. + +// + += Processing YAML + +Groovy comes with integrated support for converting between Groovy objects and YAML. The classes dedicated to +YAML serialisation and parsing are found in the `groovy.yaml` package. + +[[yaml_yamlslurper]] +== YamlSlurper + +`YamlSlurper` is a class that parses YAML text or reader content into Groovy data structures (objects) such as maps, lists and +primitive types like `Integer`, `Double`, `Boolean` and `String`. + +The class comes with a bunch of overloaded `parse` methods plus some special methods such as `parseText` +and others. For the next example we will use the `parseText` method. It parses a YAML `String` and recursively converts it to a +list or map of objects. The other `parse*` methods are similar in that they return a YAML `String` but for different parameter +types. + +[source,groovy] + +include::{rootProjectDir}/subprojects/groovy-yaml/src/spec/test/groovy/yaml/YamlParserTest.groovy --- End diff -- I'd just bring in lines 24-47 ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
Github user jwagenleitner commented on a diff in the pull request: https://github.com/apache/groovy/pull/797#discussion_r217889449 --- Diff: build.gradle --- @@ -183,6 +185,9 @@ dependencies { compile("org.apache.ivy:ivy:$ivyVersion") { transitive = false } +compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksondataformatyamlVersion" +compile "com.fasterxml.jackson.core:jackson-databind:$jacksondatabindVersion" + --- End diff -- Just curious why these 2 deps are listed here and not in `groovy-yaml/build.gradle`? ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
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 + * + * Example: + * + * 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. ---
[GitHub] groovy pull request #797: GROOVY-8794: Add groovy-yaml subproject to support...
GitHub user danielsun1106 opened a pull request: https://github.com/apache/groovy/pull/797 GROOVY-8794: Add groovy-yaml subproject to support parsing yaml You can merge this pull request into a Git repository by running: $ git pull https://github.com/danielsun1106/groovy groovy-yaml Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/797.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #797 commit 4e7712f13fbf25bda5705a5df296ef96daf37b12 Author: danielsun1106 Date: 2018-09-15T00:07:35Z Add groovy-yaml subproject to support parsing yaml ---