0

This is the JSON request that I need to pass to other API, My problem is I dont know how to create an object that can have other object inside.

What is the best approach for this, I'll be using ObjectMapper to convert the object into json like this.

{
    "request": {
        "head": {
            "version": "1.0.0",
            "function": "sample.function",
            "clientId": "clientId",
            "clientSecret": "clientSecret",
            "reqTime": "2001-07-04T12:08:56+05:30",
            "reqMsgId": "reqMessageID",
            "reserve": ""
        },
        "body": {
            "occurTime": "2018-03-04T12:08:56+08:00",
            "bizScene": "SAMPLE_BIZ",
            "envInfo": {
                "tokenId": "jkahsdhsjakdhkjsajdsahdkjsakdhsa===",
                "clientIp": "127.0.0.1",
                "appVersion": "v0.1.0",
                "terminalType": "NOP"
            },
            "extendInfo": {
                "PSID":"87943297427",
                "PSID_CreatedDate":"2018-01-04T12:08:56+08:00",
                "mobtelLinkingDate" : "2018-03-04T12:08:56+08:00",
                "mobtelUnlinkingDate" : "2018-04-04T12:08:56+08:00",
                "activeLinkedMobtel" : "123756"
            },
            "accountInfo": {
                "userMobile": "123756"
            },
            "operationInfoDTO" : {
                 "operationOrigin": "TWEETER",
            },
            "operationType": "SAMPLE",
            "operationResult": "FALSE",
        }
    },
    "signature": "signature string"
}

2 Answers2

0

I gave a name to the root Object a used this website to generate boilerplate bean object

"rootObj":{
    "request": {
        "head": {
            "version": "1.0.0",
            "function": "sample.function",
            "clientId": "clientId",
            "clientSecret": "clientSecret",
            "reqTime": "2001-07-04T12:08:56+05:30",
            "reqMsgId": "reqMessageID",
            "reserve": ""
        },
        "body": {
            "occurTime": "2018-03-04T12:08:56+08:00",
            "bizScene": "SAMPLE_BIZ",
            "envInfo": {
                "tokenId": "jkahsdhsjakdhkjsajdsahdkjsakdhsa===",
                "clientIp": "127.0.0.1",
                "appVersion": "v0.1.0",
                "terminalType": "NOP"
            },
            "extendInfo": {
                "PSID":"87943297427",
                "PSID_CreatedDate":"2018-01-04T12:08:56+08:00",
                "mobtelLinkingDate" : "2018-03-04T12:08:56+08:00",
                "mobtelUnlinkingDate" : "2018-04-04T12:08:56+08:00",
                "activeLinkedMobtel" : "123756"
            },
            "accountInfo": {
                "userMobile": "123756"
            },
            "operationInfoDTO" : {
                 "operationOrigin": "TWEETER",
            },
            "operationType": "SAMPLE",
            "operationResult": "FALSE",
        }
    },
    "signature": "signature string"
}
Rajat
  • 2,467
  • 2
  • 29
  • 38
0

There are some minor syntax errors in your JSON example in line 33 and 36.

JSON doesn't like comma after the last element of a list or dictionary.

If you remove those and use this JSON as input for http://www.jsonschema2pojo.org/ you'll get corresponding Java classes.

dpr
  • 10,591
  • 3
  • 41
  • 71