lundi 18 juillet 2016

Change a value of 1 of the attribute of json in runtime in java

My Json looks something like this:

{
"source": "somedatabasename",
"lisofobjects": [{
    "data": {
        "starttime": "1459373377",
        "age": "20",
        "name": "xyz"
    }
}]

}

As a part of validation of my API I want to pass string in age attribute for example age: "xyz". I have created a POJO objects and parsing json using gson.I want to know how should I setvalueof age at runtime.So my request code looks like this:

 protected RequestSpecification abc(classnamefromwherejsonisparsed object)
            throws JsonSyntaxException, FileNotFoundException, IOException {
            RequestSpecBuilder builder = new RequestSpecBuilder();

            builder.setContentType(ContentType.JSON); 
            builder.setBody(object.toJson(object.getallTestData()));

Thus here with getallTestData I want to change only 1 value for example age here. something like object.setAge("abc")

Aucun commentaire:

Enregistrer un commentaire