This is a simple rest web service that converts json input to xml format
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
git clone https://github.com/malathit90/json-to-xml-converter.git
mvn spring-boot:run
Go to http://localhost:8080/swagger-ui.html
. Call the api /api/v1/json2xml
.
Java version 1.8
Maven version 3.x
mvn clean test
There are 2 basic test cases.
- One test case gives valid json in
src/test/resources/example.json
file as input to the rest api and check if the generated xml is valid as given insrc/test/resources/example.xml
- The other test case gives an invalid json and checks if a bad request(400) response is given
The json to xml conversion doesn't necessarily happen in a single way. In this project, the following is the way xml conversion happens. Also, the code takes as input only valid json objects and arrays.
A json element with a number as a value should map to an XML element named <number>
.
{"a" : 5}
The above json could be mapped as :
<object>
<number name='a'>
5
</number>
</object>
A json element with a string as a value should map to an XML element named <number>
.
{"s" : "cjdb"}
The above json could be mapped as :
<object>
<string name='s'>
cjdb
</string>
</object>
A json element with a boolean (true or false) as a value should map to an XML element named <boolean>
.
{"b" : true}
The above json could be mapped as :
<object>
<boolean name='b'>
true
</boolean>
</object>
A json element with a array as a value should map to an XML element named <array>
.
[ 1, 4, "jur", { "firstName" : "xyx" }]
The above json could be mapped as :
<object>
<array>
<number>1</number>
<number>4</number>
<string>jun</string>
<object>
<string name = 'firstName'>xyx</string>
</object>
</array>
</object>
A json element with a number as a value should map to an XML element named <number>
.
{"a" : null}
The above json could be mapped as :
<object>
<null name = 'a' />
</object>
The file src/test/resources/example.json
contains a valid json input. The xml conversion for the example.json file can be found at src/main/resources/example.xml
- Spring Boot - The web framework used
- Maven - Dependency Management
- Json - Used to parse and read json
- Swagger - To create rest ui interface
We use SemVer for versioning. For the versions available, see the releases on this repository.
This project is licensed under the Apache License - see the LICENSE.md file for details