Skip to content

nurgasemetey/json-to-java

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

JSON to JAVA

Convert JSON to Java Map<String,Object> or List<Map<String,Object>>

DEMO

Use cases

  • When you need to save JSON to NoSQL each time and don't want to create class for it.

For example: you have Organization class and organization collection on MongoDB.

   String name;

And you are asked to add map information that organization could use. It is list of map configurations

One way to solve it:

Create class

   String name;
   List<MapInfo> maps;

For this you need to create class and keep collection on MongoDB. Too much for just keeping map info.

OR

Use Map<String,Object> or List<Map<String,Object>>>

   String name;
   List<Map<String,Object>> maps;

And you have following JSON to persist each time:

[ 
        {
            "default" : true,
            "imageUrl" : "/img/map/osm.png",
            "name" : "OSM",
            "type" : "Tile Layer",
            "url" : "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        }, 
        {
            "default" : false,
            "imageUrl" : "/img/map/yandexsat.png",
            "name" : "Yandex Sat",
            "type" : "Yandex Sat",
            "url" : ""
        }
]

This tool will help you to quickly convert JSON to Java Map<String,Object>.