Skip to content

Commit 03f09ba

Browse files
committed
Switch from groovy-yaml to snakeyaml due to jackson version conflicts
1 parent 4d1e042 commit 03f09ba

File tree

13 files changed

+71
-67
lines changed

13 files changed

+71
-67
lines changed

pom.xml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,6 @@
273273
<artifactId>groovy-json</artifactId>
274274
<version>${groovy.version}</version>
275275
</dependency>
276-
<dependency>
277-
<groupId>org.apache.groovy</groupId>
278-
<artifactId>groovy-yaml</artifactId>
279-
<version>${groovy.version}</version>
280-
<exclusions>
281-
<exclusion>
282-
<groupId>com.fasterxml.jackson.dataformat</groupId>
283-
<artifactId>jackson-dataformat-yaml</artifactId>
284-
</exclusion>
285-
</exclusions>
286-
</dependency>
287-
<dependency>
288-
<groupId>com.fasterxml.jackson.dataformat</groupId>
289-
<artifactId>jackson-dataformat-yaml</artifactId>
290-
<version>2.13.3</version>
291-
</dependency>
292276
<dependency>
293277
<groupId>org.apache.groovy</groupId>
294278
<artifactId>groovy-swing</artifactId>
@@ -314,6 +298,11 @@
314298
<artifactId>batik-codec</artifactId>
315299
<version>1.13</version>
316300
</dependency>
301+
<dependency>
302+
<groupId>org.yaml</groupId>
303+
<artifactId>snakeyaml</artifactId>
304+
<version>1.33</version>
305+
</dependency>
317306
<dependency>
318307
<groupId>com.lowagie</groupId>
319308
<artifactId>itext</artifactId>

src/main/groovy/geoscript/feature/io/YamlReader.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package geoscript.feature.io
33
import geoscript.geom.Geometry
44
import geoscript.geom.io.YamlReader as GeometryYamlReader
55
import geoscript.feature.Feature
6-
import groovy.yaml.YamlSlurper
6+
import org.yaml.snakeyaml.Yaml
77

88
/**
99
* Read a Feature from a GeoYaml String
@@ -15,8 +15,8 @@ class YamlReader implements Reader {
1515

1616
@Override
1717
Feature read(String str) {
18-
YamlSlurper yamlSlurper = new YamlSlurper()
19-
def obj = yamlSlurper.parseText(str)
18+
Yaml yaml = new Yaml()
19+
def obj = yaml.load(str)
2020
readFeature(obj)
2121
}
2222

src/main/groovy/geoscript/feature/io/YamlWriter.groovy

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package geoscript.feature.io
22

33
import geoscript.feature.Feature
4-
import groovy.yaml.YamlBuilder
54
import geoscript.geom.io.YamlWriter as GeometryYamlWriter
5+
import org.yaml.snakeyaml.DumperOptions
6+
import org.yaml.snakeyaml.Yaml
67

78
/**
89
* Write a Feature to a GeoYaml String
@@ -14,11 +15,15 @@ class YamlWriter implements Writer {
1415

1516
@Override
1617
String write(Feature feature) {
17-
YamlBuilder builder = new YamlBuilder()
18-
Map yaml = [type: "Feature"]
19-
yaml.putAll(build(feature))
20-
builder(yaml)
21-
builder.toString()
18+
DumperOptions options = new DumperOptions()
19+
options.indent = 2
20+
options.prettyFlow = true
21+
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
22+
options.explicitStart = true
23+
Yaml yaml = new Yaml(options)
24+
Map data = [type: "Feature"]
25+
data.putAll(build(feature))
26+
yaml.dump(data)
2227
}
2328

2429
Map build(Feature feature) {

src/main/groovy/geoscript/geom/io/YamlReader.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import geoscript.geom.MultiPoint
88
import geoscript.geom.MultiPolygon
99
import geoscript.geom.Point
1010
import geoscript.geom.Polygon
11-
import groovy.yaml.YamlSlurper
11+
import org.yaml.snakeyaml.Yaml
1212

1313
/**
1414
* Read a Geometry from a GeoYaml String
@@ -18,8 +18,8 @@ class YamlReader implements Reader {
1818

1919
@Override
2020
Geometry read(String str) {
21-
YamlSlurper yamlSlurper = new YamlSlurper()
22-
def obj = yamlSlurper.parseText(str)
21+
Yaml yaml = new Yaml()
22+
def obj = yaml.load(str)
2323
readGeometry(obj?.geometry)
2424
}
2525

src/main/groovy/geoscript/geom/io/YamlWriter.groovy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import geoscript.geom.MultiPoint
88
import geoscript.geom.MultiPolygon
99
import geoscript.geom.Point
1010
import geoscript.geom.Polygon
11-
import groovy.yaml.YamlBuilder
11+
import org.yaml.snakeyaml.DumperOptions
12+
import org.yaml.snakeyaml.Yaml
1213

1314
/**
1415
* Write a Geometry to a GeoYaml String.
@@ -18,12 +19,16 @@ class YamlWriter implements Writer {
1819

1920
@Override
2021
String write(Geometry g) {
21-
YamlBuilder builder = new YamlBuilder()
22-
Map yaml = [
22+
DumperOptions options = new DumperOptions()
23+
options.indent = 2
24+
options.prettyFlow = true
25+
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
26+
options.explicitStart = true
27+
Yaml yaml = new Yaml(options)
28+
Map data = [
2329
geometry: build(g)
2430
]
25-
builder(yaml)
26-
builder.toString()
31+
yaml.dump(data)
2732
}
2833

2934
Map build(Geometry g) {

src/main/groovy/geoscript/layer/io/YamlReader.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import geoscript.feature.Field
55
import geoscript.feature.Schema
66
import geoscript.layer.Layer
77
import geoscript.feature.io.YamlReader as FeatureYamlReader
8-
import groovy.yaml.YamlSlurper
8+
import org.yaml.snakeyaml.Yaml
99

1010
/**
1111
* Read a Layer from a GeoYaml String, File, or InputStream
@@ -17,8 +17,8 @@ class YamlReader implements Reader {
1717

1818
@Override
1919
Layer read(InputStream input) {
20-
YamlSlurper yamlSlurper = new YamlSlurper()
21-
readLayer(yamlSlurper.parse(input))
20+
Yaml yaml = new Yaml()
21+
readLayer(yaml.load(input))
2222
}
2323

2424
@Override
@@ -32,8 +32,8 @@ class YamlReader implements Reader {
3232

3333
@Override
3434
Layer read(String str) {
35-
YamlSlurper yamlSlurper = new YamlSlurper()
36-
readLayer(yamlSlurper.parseText(str))
35+
Yaml yaml = new Yaml()
36+
readLayer(yaml.load(str))
3737
}
3838

3939
private Layer readLayer(def obj) {

src/main/groovy/geoscript/layer/io/YamlWriter.groovy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package geoscript.layer.io
33
import geoscript.feature.Feature
44
import geoscript.layer.Layer
55
import geoscript.feature.io.YamlWriter as FeatureYamlWriter
6-
import groovy.yaml.YamlBuilder
6+
import org.yaml.snakeyaml.DumperOptions
7+
import org.yaml.snakeyaml.Yaml
78

89
/**
910
* Write a Layer to a GeoYaml String, File, or OutputStream
@@ -27,15 +28,19 @@ class YamlWriter implements Writer {
2728

2829
@Override
2930
String write(Layer layer) {
30-
YamlBuilder builder = new YamlBuilder()
31-
Map yaml = [
31+
DumperOptions options = new DumperOptions()
32+
options.indent = 2
33+
options.prettyFlow = true
34+
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
35+
options.explicitStart = true
36+
Yaml yaml = new Yaml(options)
37+
Map data = [
3238
type: "FeatureCollection",
3339
features: layer.collectFromFeature { Feature feature ->
3440
featureYamlWriter.build(feature)
3541
}
3642
]
37-
builder(yaml)
38-
builder.toString()
43+
yaml.dump(data)
3944
}
4045

4146
}

src/test/groovy/geoscript/feature/FeatureTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ class FeatureTest {
324324
Schema s1 = new Schema("houses", [new Field("geom","Point"), new Field("name","string"), new Field("price","float")])
325325
Feature f1 = new Feature([new Point(111,-47), "House", 12.5], "house1", s1)
326326
assertEquals("""---
327-
type: "Feature"
327+
type: Feature
328328
properties:
329-
name: "House"
329+
name: House
330330
price: 12.5
331331
geometry:
332-
type: "Point"
332+
type: Point
333333
coordinates:
334334
- 111.0
335335
- -47.0

src/test/groovy/geoscript/feature/io/YamlWriterTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class YamlWriterTest {
1515
Feature feature = new Feature([new Point(111,-47), "House", 12.5], "house1", schema)
1616
YamlWriter writer = new YamlWriter()
1717
String expected = """---
18-
type: "Feature"
18+
type: Feature
1919
properties:
20-
name: "House"
20+
name: House
2121
price: 12.5
2222
geometry:
23-
type: "Point"
23+
type: Point
2424
coordinates:
2525
- 111.0
2626
- -47.0

src/test/groovy/geoscript/geom/GeometryTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class GeometryTest {
291291
Geometry g = Geometry.fromWKT("POINT (111 -47)")
292292
assertEquals """---
293293
geometry:
294-
type: "Point"
294+
type: Point
295295
coordinates:
296296
- 111.0
297297
- -47.0

0 commit comments

Comments
 (0)