Search code examples
jsonjacksonpojonest-api

JSON to POJO for google nest response


I want to convert the json reponse from google nest thermostat into POJO for further use.

The thermostat array contains an array of device id's holding the actual device values. I am not sure how to create POJO model for this thermostat list, could anyone guide me in the right direction?

This is the Json reponse i get form nest.

{
  "thermostats": {
    "A5K29Sp2Nr1IghCYK3Jj7MF0a0pXuhxk": {
      "humidity": 65,
      "locale": "en-US",
      "temperature_scale": "C",
      "is_using_emergency_heat": false,
      "has_fan": true,
      "software_version": "4.1",
      "has_leaf": true,
      "where_id": "gPn37UwCFT5l1y8iHzATIcLKJhFieKtX0Y1GeGA_DZ5X6N7db7FRgw",
      "device_id": "A5K29Sp2Nr1IghCYK3Jj7MF0a0pXuhxk",
      "name": "Basement (FB9B)",
      "can_heat": true,
      "can_cool": false,
      "hvac_mode": "heat",
      "target_temperature_c": 21.5,
      "target_temperature_f": 71,
      "target_temperature_high_c": 26,
      "target_temperature_high_f": 79,
      "target_temperature_low_c": 19,
      "target_temperature_low_f": 66,
      "ambient_temperature_c": 24.5,
      "ambient_temperature_f": 76,
      "away_temperature_high_c": 24,
      "away_temperature_high_f": 76,
      "away_temperature_low_c": 12.5,
      "away_temperature_low_f": 55,
      "structure_id": "kg24pb09IIaJjREeEj6RmBAASwE9VgI92bfPJoIZC4yHGP2s9hqX1g",
      "fan_timer_active": false,
      "fan_timer_timeout": "1970-01-01T00:00:00.000Z",
      "name_long": "Basement Thermostat (FB9B)",
      "is_online": true,
      "hvac_state": "off"
    }
  }
}

Solution

  • The contents of thermostat in the json should be modelled as Map like Map<String,Object>