public String parse()

in oneandone/src/main/java/org/apache/jclouds/oneandone/rest/util/ServerApplianceParser.java [44:107]


   public String parse(String json, String prefix, String key) {

      SingleServerAppliance result = null;
      Type mapType = new TypeToken<Map<String, Object>>() {
      }.getType();
      Map<String, Object> jsonMap = jsonBinder.fromJson(json, mapType);
      List<Object> dcs = cast(jsonMap.get("available_datacenters"));
      List<Object> categories = cast(jsonMap.get("categories"));
      Class<? extends Object> typeName = dcs.get(0).getClass();
      List<SingleServerAppliance.AvailableDataCenters> list = new ArrayList<SingleServerAppliance.AvailableDataCenters>();
      List<String> cats = null;

      if (typeName != String.class) {
         for (Object t : dcs) {
            LinkedTreeMap map = (LinkedTreeMap) t;
            list.add(SingleServerAppliance.AvailableDataCenters.create(map.get("id").toString(), map.get("name").toString()));
         }
         if (categories != null) {
            cats = new ArrayList<String>();
            for (Object t : categories) {
               cats.add(t.toString());
            }
         }

      } else {
         for (Object t : dcs) {
            list.add(SingleServerAppliance.AvailableDataCenters.create(t.toString(), ""));
         }
         if (categories != null) {
            cats = new ArrayList<String>();
            for (Object t : categories) {
               cats.add(t.toString());
            }
         }
      }
      String osInstallationBase = jsonMap.get("os_installation_base") != null ? jsonMap.get("os_installation_base").toString() : null;
      Types.OSFamliyType osFamily = jsonMap.get("os_family") != null ? Types.OSFamliyType.fromValue(jsonMap.get("os_family").toString()) : null;
      String os = jsonMap.get("os") != null ? jsonMap.get("os").toString() : null;
      String osVersion = jsonMap.get("os_version") != null ? jsonMap.get("os_version").toString() : null;
      Types.OSImageType imageType = jsonMap.get("os_image_type") != null ? Types.OSImageType.fromValue(jsonMap.get("os_image_type").toString()) : null;
      Types.ApplianceType type = jsonMap.get("type") != null ? Types.ApplianceType.fromValue(jsonMap.get("type").toString()) : null;
      String state = jsonMap.get("state") != null ? jsonMap.get("state").toString() : null;
      String version = jsonMap.get("version") != null ? jsonMap.get("version").toString() : null;
      String eula_url = jsonMap.get("eula_url") != null ? jsonMap.get("eula_url").toString() : null;

      result = SingleServerAppliance.builder().availableDataCenters(list)
              .categories(cats)
              .eulaUrl(eula_url)
              .id(jsonMap.get("id").toString())
              .minHddSize((int) Double.parseDouble(jsonMap.get("min_hdd_size").toString()))
              .os(os)
              .name(jsonMap.get("name").toString())
              .osArchitecture((int) Double.parseDouble(jsonMap.get("os_architecture").toString()))
              .osFamily(osFamily)
              .osImageType(imageType)
              .osInstallationBase(osInstallationBase)
              .osVersion(osVersion)
              .state(state)
              .type(type)
              .version(version)
              .build();

      return jsonBinder.toJson(result);
   }