0

I have a json data (that i can't change) stored in my nosql Mongodb database. This is how the data looks like :

{"scans" : {
        "Bkav" : {
            "detected" : false,
            "version" : "1.3.0.4924",
            "result" : null,
            "update" : "20140214"
        },
        "MicroWorld" : {
            "detected" : false,
            "version" : "12.0.250.0",
            "result" : null,
            "update" : "20140216"
        },
        "nProtect" : {
            "detected" : false,
            "version" : "2014-02-16.01",
            "result" : null,
            "update" : "20140216"
        }
  }
}

what i'm trying to do is to create a rest webservice based on spring boot in order to retrieve the data stored in mongo, so i need to set up my models (based on the json format ) and this is what i came up with :

public class Scans
{
    @Id
    private String id; 
    private Bkav Bkav;
    private NProtect nProtect;
    private MicroWorld-eScan MicroWorld-eScan;

    //getters and setters

    @Override
    public String toString()
    {
        return "ClassPojo [Bkav = "+Bkav+", nProtect = "+nProtect+", MicroWorld-eScan = "+MicroWorld-eScan+"]";
    }
 }

And for each scanner (Bkav, nProtect, MicroWorld-escan) i have this same model :

public class "scanner" //that may be one of the above names;
{
    private String update;
    private String result;
    private String detected;
    private String version;
    //getters and setters
    @Override
    public String toString()
    {
        return "ClassPojo [update = "+update+", result = "+result+", detected = "+detected+", version = "+version+"]";
    }
}

So is it possible to create only one class for all the scanners since i have more than the ones i listed in my question

1
  • I think your JSON needs to be deserialized into a Map<String, Scanner> Commented Jul 26, 2017 at 21:02

1 Answer 1

1

First, MicroWorld-eScan is not a valid class or variable name

In my experience, you would need to have this model

public class Scans {
    @Id
    private transient String id; 
    private TreeMap<String, Scanner> scans;

    // for example
    public Bkav getBkav() {
        return map.get("Bkav");
    } 

I would recommend a different name to not conflict with java.util.Scanner

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.