[prev in list] [next in list] [prev in thread] [next in thread]
List: groovy-user
Subject: [groovy-user] Unexpected behavior with ConfigObject.writeTo
From: Spike Washburn <spike () washburnnet ! com>
Date: 2009-03-30 22:04:58
Message-ID: 160274c80903301504n4bcb536bq551a6b23e30f6ba4 () mail ! gmail ! com
[Download RAW message or body]
I'm pulling my hair out with a behavior I'm seeing in ConfigObject that I
don't understand and am trying to determine if this is the expected behavior
or a bug. I realize this is a very basic scenario, so I must be completely
misunderstanding how this is supposed to work, but any insight would be much
appreciated.
When saving a configObject constructed in the following way:
def config = new ConfigObject();
config.node1.node2.node3.prop1 = "val1"
config.node1.node2.node3.prop2 = "val2"
I expected the following file to be produced:
node1{
node2{
node3 {
prop1="val1"
prop2="val2"
}
}
}
But instead, the following file is produced:
node3 {
prop1="val1"
prop2="val2"
}
Slurping this file back in then fails to return node1.node2.node3.prop1
because the node1.node2 property prefixes are gone.
This fails on Groovy Version: 1.6.0 and 1.5.6 (JVM: 1.5.0_12)
=== ConfigObject Test ===
def file1 = "test.config"
def config = new ConfigObject();
config.node1.node2.node3.prop1 = "val1"
config.node1.node2.node3.prop2 = "val2"
new File(file1).withWriter { writer ->
config.writeTo(writer)
}
def config2 = new ConfigSlurper().parse(new File(file1).toURL())
assert(config2.node1.node2.node3.prop1 == config.node1.node2.node3.prop1)
//<-- test fails here
assert(config2.node1.node2.node3.prop2 == config.node1.node2.node3.prop2)
[Attachment #3 (text/html)]
I'm pulling my hair out with a behavior I'm seeing in ConfigObject that I \
don't understand and am trying to determine if this is the expected behavior or a \
bug. I realize this is a very basic scenario, so I must be completely \
misunderstanding how this is supposed to work, but any insight would be much \
appreciated.<br> <br><br>When saving a configObject constructed in the following \
way:<br> def config = new ConfigObject();<br> config.node1.node2.node3.prop1 = \
"val1"<br> config.node1.node2.node3.prop2 = "val2"<br><br> I \
expected the following file to be produced:<br>node1{<br> node2{<br> node3 \
{<br> prop1="val1"<br> prop2="val2"<br> \
}<br> }<br>}<br><br><br>But instead, the following file is produced:<br> node3 \
{<br> prop1="val1"<br> prop2="val2"<br>}<br><br>Slurping \
this file back in then fails to return node1.node2.node3.prop1 because the \
node1.node2 property prefixes are gone.<br><br>This fails on Groovy Version: 1.6.0 \
and 1.5.6 (JVM: 1.5.0_12)<br> <br><br>=== ConfigObject Test ===<br>def file1 = \
"test.config"<br>def config = new \
ConfigObject();<br>config.node1.node2.node3.prop1 = \
"val1"<br>config.node1.node2.node3.prop2 = "val2"<br>new \
File(file1).withWriter { writer -><br> config.writeTo(writer)<br>}<br>def config2 \
= new ConfigSlurper().parse(new \
File(file1).toURL())<br>assert(config2.node1.node2.node3.prop1 == \
config.node1.node2.node3.prop1) //<-- test fails \
here<br>assert(config2.node1.node2.node3.prop2 == config.node1.node2.node3.prop2)<br>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic