StoragePoolSerializationAdapter implements JsonSerializer<StoragePool>,
        JsonDeserializer<StoragePool> { @Override public StoragePool deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonElement allocatedCapacity = json.getAsJsonObject().remove(StoragePool.ALLOCATED_CAPACITY_FIELD); StoragePool storagePool = gson().fromJson(json, StoragePool.class); if (allocatedCapacity.isJsonPrimitive()) { storagePool.setAllocatedCapacity(allocatedCapacity.getAsString()); } else { storagePool.setAllocatedCapacityDetails(gson().fromJson(allocatedCapacity, AllocatedCapacity.class)); } return storagePool; }  @Override StoragePool deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context); @Override JsonElement serialize(StoragePool src, Type typeOfSrc, JsonSerializationContext context);  }
@Test public void shouldDeserializeStoragePool() { StoragePoolSerializationAdapter adapter = new StoragePoolSerializationAdapter(); JsonParser parser = new JsonParser(); StoragePool storagePool = adapter.deserialize(parser.parse(storagePoolJson), null, null); assertThat(storagePool.getType(), is(equalTo(ResourceCategory.RC_STORAGE_POOL))); assertThat(storagePool.getAllocatedCapacityDetails().getSnapshotAllocatedCapacity(), is(nullValue())); assertThat(storagePool.getAllocatedCapacityDetails().getVolumeAllocatedCapacity(), is(nullValue())); }
@Test public void shouldDeserializeStoragePoolV2() { StoragePoolSerializationAdapter adapter = new StoragePoolSerializationAdapter(); JsonParser parser = new JsonParser(); StoragePool storagePool = adapter.deserialize(parser.parse(storagePoolV2Json), null, null); assertThat(storagePool.getType(), is(equalTo(ResourceCategory.RC_STORAGE_POOL_V200))); assertThat(storagePool.getAllocatedCapacityDetails().getSnapshotAllocatedCapacity(), is(notNullValue())); assertThat(storagePool.getAllocatedCapacityDetails().getVolumeAllocatedCapacity(), is(notNullValue())); }