예제 #1
0
    @Override
    public Server deserialize(
        JsonElement jsonElement, Type type, JsonDeserializationContext context)
        throws JsonParseException {
      Server serverBase;

      // Servers can be created without an image so test if an image object is returned
      if (jsonElement.getAsJsonObject().get("image").isJsonObject()) {
        serverBase = apply((ServerInternal) context.deserialize(jsonElement, ServerInternal.class));
      } else {
        serverBase =
            apply(
                (ServerInternalWithoutImage)
                    context.deserialize(jsonElement, ServerInternalWithoutImage.class));
      }

      Server.Builder<?> result = Server.builder().fromServer(serverBase);
      ServerExtendedStatus extendedStatus =
          context.deserialize(jsonElement, ServerExtendedStatus.class);
      if (!Objects.equal(extendedStatus, ServerExtendedStatus.builder().build())) {
        result.extendedStatus(extendedStatus);
      }
      ServerExtendedAttributes extraAttributes =
          context.deserialize(jsonElement, ServerExtendedAttributes.class);
      if (!Objects.equal(extraAttributes, ServerExtendedAttributes.builder().build())) {
        result.extendedAttributes(extraAttributes);
      }
      return result.build();
    }
예제 #2
0
 public T fromServerExtendedStatus(ServerExtendedStatus in) {
   return this.taskState(in.getTaskState())
       .vmState(in.getVmState())
       .powerState(in.getPowerState());
 }