StoragePoolSerializationAdapter implements JsonSerializer<StoragePool>,
        JsonDeserializer<StoragePool> { @Override public JsonElement serialize(StoragePool src, Type typeOfSrc, JsonSerializationContext context) { JsonElement jsonElement = gson().toJsonTree(src); if (ResourceCategory.RC_STORAGE_POOL.equalsIgnoreCase(src.getType())) { JsonObject jsonObject = jsonElement.getAsJsonObject(); jsonObject.remove(StoragePool.ALLOCATED_CAPACITY_FIELD); jsonObject.addProperty(StoragePool.ALLOCATED_CAPACITY_FIELD, src.getAllocatedCapacity()); } return jsonElement; }  @Override StoragePool deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context); @Override JsonElement serialize(StoragePool src, Type typeOfSrc, JsonSerializationContext context);  }
@Test public void shouldSerializeStoragePool() throws ParseException { StoragePoolSerializationAdapter adapter = new StoragePoolSerializationAdapter(); StoragePool storagePool = this.buildStoragePool(); JsonObject serializedStoragePool = adapter.serialize(storagePool, null, null).getAsJsonObject(); assertThat(serializedStoragePool.getAsJsonPrimitive("type").getAsString(), is(equalTo(ResourceCategory.RC_STORAGE_POOL))); assertThat(serializedStoragePool.get(StoragePool.ALLOCATED_CAPACITY_FIELD).isJsonPrimitive(), is(equalTo(Boolean.TRUE))); }
@Test public void shouldSerializeStoragePoolV2() throws ParseException { StoragePoolSerializationAdapter adapter = new StoragePoolSerializationAdapter(); StoragePool storagePool = this.buildStoragePoolV2(); JsonObject serializedStoragePool = adapter.serialize(storagePool, null, null).getAsJsonObject(); assertThat(serializedStoragePool.getAsJsonPrimitive("type").getAsString(), is(equalTo(ResourceCategory.RC_STORAGE_POOL_V200))); assertThat(serializedStoragePool.get(StoragePool.ALLOCATED_CAPACITY_FIELD).isJsonPrimitive(), is(equalTo(Boolean.FALSE))); }