Giter Club home page Giter Club logo

json-to-xml-converter's Introduction

Json2Xml

This is a simple rest web service that converts json input to xml format

Getting Started

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.

Prerequisites

Java version 1.8
Maven version 3.x

Running the tests

mvn clean test

Break down into end to end tests

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 in src/test/resources/example.xml
  • The other test case gives an invalid json and checks if a bad request(400) response is given

How Json to xml conversion happens

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.

Json Number

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> 

Json String

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> 

Json Boolean

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> 

Json Array

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> 

Json NULL

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> 

Example files

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

Built With

  • Spring Boot - The web framework used
  • Maven - Dependency Management
  • Json - Used to parse and read json
  • Swagger - To create rest ui interface

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

License

This project is licensed under the Apache License - see the LICENSE.md file for details

json-to-xml-converter's People

Contributors

malathit avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.