Bidirectional conversion of JSON <==> XML seems off.
Given the following insert changeSet in JSON from the source:
- {
- "databaseChangeLog": [
- {
- "changeSet": {
- "id": "datatypetest-2",
- "author": "nvoxland",
- "validCheckSums": ["ANY"],
- "changes": [
- {
- "insert": {
- "tableName": "dataTypeTest",
- "columns": [
- {
- "column": {
- "name": "id",
- "valueNumeric": 1
- }
- },
- {
- "column": {
- "name": "dateCol",
- "valueDate": "2007-08-09"
- }
- },
- {
- "column": {
- "name": "timeCol",
- "valueDate": "13:14:15"
- }
- },
- {
- "column": {
- "name": "dateTimeCol",
- "valueDate": "2007-08-09T13:14:15"
- }
- },
- {
- "column": {
- "name": "bigintcol",
- "valueNumeric": 2
- }
- }
- ]
- }
- },
- {
- "insert": {
- "tableName": "dataTypeTest",
- "columns": [
- {
- "column": {
- "name": "id",
- "valueNumeric": 2
- }
- },
- {
- "column": {
- "name": "dateCol",
- "valueDate": "current_datetime"
- }
- },
- {
- "column": {
- "name": "timeCol",
- "valueComputed": "current_datetime"
- }
- },
- {
- "column": {
- "name": "dateTimeCol",
- "valueDate": "current_datetime"
- }
- },
- {
- "column": {
- "name": "bigintcol",
- "valueNumeric": 2
- }
- }
- ]
- }
- }
- ]
- }
- }
- ]
- }
When converted to XML using a the JQuery json2xml converter (and others), turns into the following XML
- <?xml version="1.0" encoding="utf-8"?>
- <databaseChangeLog>
- <changeSet>
- <validCheckSums>ANY</validCheckSums>
- <id>datatypetest-2</id>
- <author>nvoxland</author>
- <changes>
- <insert>
- <tableName>dataTypeTest</tableName>
- <columns>
- <column>
- <valueNumeric>1</valueNumeric>
- <name>id</name>
- </column>
- </columns>
- <columns>
- <column>
- <name>dateCol</name>
- <valueDate>2007-08-09</valueDate>
- </column>
- </columns>
- <columns>
- <column>
- <name>timeCol</name>
- <valueDate>13:14:15</valueDate>
- </column>
- </columns>
- <columns>
- <column>
- <name>dateTimeCol</name>
- <valueDate>2007-08-09T13:14:15</valueDate>
- </column>
- </columns>
- <columns>
- <column>
- <valueNumeric>2</valueNumeric>
- <name>bigintcol</name>
- </column>
- </columns>
- </insert>
- </changes>
- <changes>
- <insert>
- <tableName>dataTypeTest</tableName>
- <columns>
- <column>
- <valueNumeric>2</valueNumeric>
- <name>id</name>
- </column>
- </columns>
- <columns>
- <column>
- <name>dateCol</name>
- <valueDate>current_datetime</valueDate>
- </column>
- </columns>
- <columns>
- <column>
- <name>timeCol</name>
- <valueComputed>current_datetime</valueComputed>
- </column>
- </columns>
- <columns>
- <column>
- <name>dateTimeCol</name>
- <valueDate>current_datetime</valueDate>
- </column>
- </columns>
- <columns>
- <column>
- <valueNumeric>2</valueNumeric>
- <name>bigintcol</name>
- </column>
- </columns>
- </insert>
- </changes>
- </changeSet>
- </databaseChangeLog>
And the same insert changeSet in XML from the source:
- <?xml version="1.0" encoding="UTF-8"?>
- <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
- <changeSet author="nvoxland" id="datatypetest-2">
- <validCheckSum>ANY</validCheckSum>
- <insert tableName="dataTypeTest">
- <column name="id" valueNumeric="1"/>
- <column name="dateCol" valueDate="2007-08-09"/>
- <column name="timeCol" valueDate="13:14:15"/>
- <column name="dateTimeCol" valueDate="2007-08-09T13:14:15"/>
- <column name="bigintcol" valueNumeric="2"/>
- </insert>
- <insert dbms="!derby" tableName="dataTypeTest">
- <column name="id" valueNumeric="2"/>
- <column name="dateCol" valueDate="current_datetime"/>
- <column name="timeCol" valueComputed="current_datetime"/>
- <column name="dateTimeCol" valueDate="current_datetime"/>
- <column name="bigintcol" valueNumeric="2"/>
- </insert>
- </changeSet>
- </databaseChangeLog>
When converted using the JQuery xml2json, produces the following JSON:
- {
- "databaseChangeLog": {
- "changeSet": {
- "author": "nvoxland",
- "id": "datatypetest-2",
- "validCheckSum": "ANY",
- "insert": [
- {
- "tableName": "dataTypeTest",
- "column": [
- {
- "name": "id",
- "valueNumeric": "1"
- },
- {
- "name": "dateCol",
- "valueDate": "2007-08-09"
- },
- {
- "name": "timeCol",
- "valueDate": "13:14:15"
- },
- {
- "name": "dateTimeCol",
- "valueDate": "2007-08-09T13:14:15"
- },
- {
- "name": "bigintcol",
- "valueNumeric": "2"
- }
- ]
- },
- {
- "dbms": "!derby",
- "tableName": "dataTypeTest",
- "column": [
- {
- "name": "id",
- "valueNumeric": "2"
- },
- {
- "name": "dateCol",
- "valueDate": "current_datetime"
- },
- {
- "name": "timeCol",
- "valueComputed": "current_datetime"
- },
- {
- "name": "dateTimeCol",
- "valueDate": "current_datetime"
- },
- {
- "name": "bigintcol",
- "valueNumeric": "2"
- }
- ]
- }
- ]
- }
- }
- }
I'm confused by this apparent discrepancy. It seems to prevent automated conversions from one format to another, which seems like a natural option given the relative compatibility of JSON, XML and YAML. I recognize that there are well-known problems with these conversions, but those don't seem to be what is at play here.
I'd love to understand the thinking on this - it looks to me that you implemented YAML and got JSON, rather than deriving from your original XML structure.