简体   繁体   中英

Parse Complex JSON with Object Mapper

I am trying to parse complex JSON response using REST template.

`[
{
"message": "address_matched",
"location": "433 merwyn road merion station pa",
"resultcountformatted": "488",
"resultcount": 488,
"pagerdata": {
"Current": 1,
"Pages": 55,
"ResultStart": 0,
"ResultEnd": 0,
"TotalResults": 488,
"PageList": [
{
"PageNumber": "1",
"PageURL": "/realestatehomesforsale/19066-p001.html?query=geodist-aorder"
},
{
"PageNumber": "2",
"PageURL": "/realestatehomesforsale/19066-p002.html?query=geodist-aorder"
},
{
"PageNumber": "3",
"PageURL": "/realestatehomesforsale/19066-p003.html?query=geodist-aorder"
},
{
"PageNumber": "4",
"PageURL": "/realestatehomesforsale/19066-p004.html?query=geodist-aorder"
},
{
"PageNumber": "5",
"PageURL": "/realestatehomesforsale/19066-p005.html?query=geodist-aorder"
},
{
"PageNumber": "6",
"PageURL": "/realestatehomesforsale/19066-p006.html?query=geodist-aorder"
},
{
"PageNumber": "7",
"PageURL": "/realestatehomesforsale/19066-p007.html?query=geodist-aorder"
},
{
"PageNumber": "8",
"PageURL": "/realestatehomesforsale/19066-p008.html?query=geodist-aorder"
},
{
"PageNumber": "9",
"PageURL": "/realestatehomesforsale/19066-p009.html?query=geodist-aorder"
},
{
"PageNumber": "10",
"PageURL": "/realestatehomesforsale/19066-p010.html?query=geodist-aorder"
},
{
"PageNumber": "..."
},
{
"PageNumber": "20",
"PageURL": "/realestatehomesforsale/19066-p020.html?query=geodist-aorder"
},
{
"PageNumber": "30",
"PageURL": "/realestatehomesforsale/19066-p030.html?query=geodist-aorder"
},
{
"PageNumber": "40",
"PageURL": "/realestatehomesforsale/19066-p040.html?query=geodist-aorder"
},
{
"PageNumber": "50",
"PageURL": "/realestatehomesforsale/19066-p050.html?query=geodist-aorder"
},
{
"PageNumber": "55",
"PageURL": "/realestatehomesforsale/19066-p055.html?query=geodist-aorder"
}
],
"PagesPerSet": 10,
"ItemsPerPage": 9
},
"lat": 40.004202,
"office": {
"OfficeListingsCount": 0,
"OfficeListings": [],
"PageNumber": 1,
"PageSize": 6,
"OfficeName": "quantro.remax.com",
"VirtualOfficeAllowed": true,
"ShowListingInformationSponsoredby": true,
"OfficeDetailURL": "/realestateofficerealtor/quantroremaxcom-id68000000.html",
"Address1": "",
"City": "",
"State": "",
"Zip": "",
"Phone": "",
"LicenseNumber": "",
"OfficeID": 68000000,
"PhotoRef": "https://matrix.remax.net/profileimages/balloonImage.jpg",
"HasOfficeOwners": false,
"IsGeoCoded": false,
"OfficeGeoCheckLevelCode": 0,
"SiteURL": "quantro.remax.com",
"Protocol": "https",
"SiteID": "68000000",
"Lat": 0,
"Lng": 0,
"AgentCount": 0,
"HideSocialWall": false,
"ShowListings": false,
"OfficeOwners": [],
"OfficeManagers": [],
"SearchSiteURL": "www.remax.com",
"ShowDetailsURL": false,
"ShowLogo": true,
"ShowContact": true,
"AccountID": 0,
"TagLine": "",
"MowSiteID": 0,
"IsMow": false
},
"long": -75.254086
},
[
{
"IsHomeValue": true,
"IsForeclosure": false,
"SoldDateFormatted": "6/27/2002",
"PriceFormatted": "380,000",
"AVMPriceFormatted": "597,668",
"ListingDetailURL": "/realestatehomesforsale/433-merwyn-rd-merion-station-pa-19066-gid400024907235.html",
"GlobalListingDetailURL": "/realestatehomesforsale/433-merwyn-rd-merion-station-pa-19066-gid400024907235.html",
"sz_id": 400024907235,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "433 MERWYN RD",
"City": "MERION STATION",
"street_name": "MERWYN RD",
"State": "PA",
"Zip": "19066",
"SqFt": "2897",
"SqFtFormatted": "2,897",
"avm": "597668",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1958,
"BedRooms": 5,
"BathRooms": 4,
"Latitude": 40.004202,
"Longitude": -75.254086
},
{
"IsHomeValue": true,
"IsForeclosure": false,
"SoldDateFormatted": "7/14/1999",
"PriceFormatted": "245,000",
"AVMPriceFormatted": "516,630",
"ListingDetailURL": "/realestatehomesforsale/429-merwyn-rd-merion-station-pa-19066-gid400024907236.html",
"GlobalListingDetailURL": "/realestatehomesforsale/429-merwyn-rd-merion-station-pa-19066-gid400024907236.html",
"sz_id": 400024907236,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "429 MERWYN RD",
"City": "MERION STATION",
"street_name": "MERWYN RD",
"State": "PA",
"Zip": "19066",
"SqFt": "2313",
"SqFtFormatted": "2,313",
"avm": "516630",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1958,
"BedRooms": 4,
"BathRooms": 3,
"Latitude": 40.004024,
"Longitude": -75.253908
},
{
"IsHomeValue": true,
"IsForeclosure": false,
"PriceFormatted": "300,000",
"AVMPriceFormatted": "581,476",
"ListingDetailURL": "/realestatehomesforsale/516-narberth-ave-merion-station-pa-19066-gid400024908056.html",
"GlobalListingDetailURL": "/realestatehomesforsale/516-narberth-ave-merion-station-pa-19066-gid400024908056.html",
"sz_id": 400024908056,
"ListingID": 0,
"ValueListingTypeID": 0,
"Address": "516 NARBERTH AVE",
"City": "MERION STATION",
"street_name": "NARBERTH AVE",
"State": "PA",
"Zip": "19066",
"SqFt": "2996",
"SqFtFormatted": "2,996",
"avm": "581476",
"History": [],
"ValueSearchType": 1,
"ValueSearchTypeText": "NOT FOR SALE",
"SiteID": 0,
"YearBuilt": 1920,
"BedRooms": 5,
"BathRooms": 4,
"Latitude": 40.000613,
"Longitude": -75.258385
}
]
]`

For the above response trying to figure out the POJO, I tried couple POJO hierarchy to parse these Json not able figure out, Can someone suggest me the POJO to parse it

Actually JSON response has List of JSON array contains Object and again array without object and array name bit difficult to map using object mapper any the mapping library to this response, Can we get help to build Object Model for this response.

You have three options:

  1. Check with the API provider if there is a Swagger/OpenAPI definition for the API. If there is you can generate the code using Swagger Codegen .

  2. Look up the documentation of the API and write the Java classes according to the model defined there by hand.

  3. If you don't have the time for point 2 then you can use quicktype which generates code directly from a JSON example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM