コード例 #1
1
ファイル: Segment.java プロジェクト: GameModsBR/MyTown2
    private SegmentItem deserializeItem(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }

      SegmentItem segment = new SegmentItem();

      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<ItemType>() {},
              new TypeToken<List<ItemType>>() {}.getType()));
      json.remove("actions");

      if (json.has("isAdjacent")) {
        segment.isAdjacent = json.get("isAdjacent").getAsBoolean();
        json.remove("isAdjacent");
      }

      if (json.has("clientUpdate")) {
        JsonObject jsonClientUpdate = json.get("clientUpdate").getAsJsonObject();
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume) context.deserialize(jsonClientUpdate.get("coords"), Volume.class));
        if (jsonClientUpdate.has("directional")) {
          segment.directionalClientUpdate = jsonClientUpdate.get("directional").getAsBoolean();
        }
        json.remove("clientUpdate");
      }

      return segment;
    }
コード例 #2
0
ファイル: NovaParserModule.java プロジェクト: kwart/jclouds
    @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();
    }
コード例 #3
0
 @Override
 public Versioning deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   if (!json.isJsonObject()) {
     throw new JsonParseException("Element was not an object");
   }
   JsonObject obj = json.getAsJsonObject();
   VersioningType type = context.deserialize(obj.get("type"), VersioningType.class);
   JsonElement params = obj.get("params");
   if (type == null) {
     type = VersioningType.NONE;
   }
   switch (type) {
     case EXTERNAL:
       return new VersioningExternal(
           type, context.deserialize(params, VersioningExternal.Params.class));
     case SIMPLE:
       return new VersioningSimple(
           type, context.deserialize(params, VersioningSimple.Params.class));
     case STAGGERED:
       return new VersioningStaggered(
           type, context.deserialize(params, VersioningStaggered.Params.class));
     case TRASHCAN:
       return new VersioningTrashCan(
           type, context.deserialize(params, VersioningTrashCan.Params.class));
     case NONE:
     default:
       return new VersioningNone(type);
   }
 }
コード例 #4
0
 @Override
 public Object deserialize(JsonElement element, Type type, JsonDeserializationContext jdc)
     throws JsonParseException {
   if (element.isJsonPrimitive()) {
     JsonPrimitive primitive = element.getAsJsonPrimitive();
     if (primitive.isBoolean()) {
       return primitive.getAsBoolean();
     } else if (primitive.isNumber()) {
       return primitive.getAsNumber();
     } else {
       return primitive.getAsString();
     }
   } else if (element.isJsonArray()) {
     Object[] array = jdc.deserialize(element, Object[].class);
     return new ArrayList<Object>(Arrays.asList(array));
   } else if (element.isJsonObject()) {
     Set<Entry<String, JsonElement>> entrySet = element.getAsJsonObject().entrySet();
     Map<String, Object> map = new HashMap<String, Object>();
     for (Entry<String, JsonElement> entry : entrySet) {
       map.put(entry.getKey(), jdc.deserialize(entry.getValue(), Object.class));
     }
     return map;
   }
   throw new IllegalArgumentException(
       "Illegal pipeline format, expecting either a primitive type or an array or an object");
 }
コード例 #5
0
ファイル: DataJSON.java プロジェクト: borysiam/Troia-Server
    @Override
    public Data<T> deserialize(
        JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext)
        throws JsonParseException {
      Data<T> data = new Data<T>();
      JsonObject jo = jsonElement.getAsJsonObject();
      for (JsonElement je : jo.get("workers").getAsJsonArray()) {
        Worker<T> worker = new Worker<T>(je.getAsString());
        data.addWorker(worker);
      }
      for (JsonElement je : jo.get("objects").getAsJsonArray()) {
        LObject<T> object = jsonDeserializationContext.deserialize(je, LObject.class);
        data.addObject((object));
      }
      for (JsonElement je : jo.get("goldObjects").getAsJsonArray()) {
        LObject<T> object = jsonDeserializationContext.deserialize(je, LObject.class);
        data.addGoldObject((object));
      }
      for (JsonElement je : jo.get("evaluationObjects").getAsJsonArray()) {
        LObject<T> object = jsonDeserializationContext.deserialize(je, LObject.class);
        data.addEvaluationObject((object));
      }

      for (JsonElement je : jo.get("assigns").getAsJsonArray()) {
        ShallowAssign<T> sassign = jsonDeserializationContext.deserialize(je, ShallowAssign.class);

        Worker<T> worker = data.getWorker(sassign.worker);
        LObject<T> object = data.getObject(sassign.object);
        data.addAssign(new AssignedLabel<T>(worker, object, sassign.label));
      }

      return data;
    }
  @Override
  public JsonRpcResponse deserialize(
      JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();

    String id = jsonObject.get(ResponseProperty.ID.key()).getAsString();
    if (jsonObject.has(ResponseProperty.ERROR.key())) {
      JsonElement errorObject = jsonObject.get(ResponseProperty.ERROR.key());
      String errorMessage = errorObject.getAsJsonObject().get("message").getAsString();
      return JsonRpcResponse.error(id, errorMessage);
    }

    // Deserialize the data.
    Map<ParamsProperty, Object> properties = new HashMap<ParamsProperty, Object>();
    JsonElement data = jsonObject.get(ResponseProperty.DATA.key());
    if (data != null && data.isJsonObject()) {
      for (Entry<String, JsonElement> parameter : data.getAsJsonObject().entrySet()) {
        ParamsProperty parameterType = ParamsProperty.fromKey(parameter.getKey());
        if (parameterType == null) {
          // Skip this unknown parameter.
          continue;
        }
        Object object = null;
        if (parameterType == ParamsProperty.BLIPS) {
          Type blipMapType = new TypeToken<Map<String, BlipData>>() {}.getType();
          object = context.deserialize(parameter.getValue(), blipMapType);
        } else {
          object = context.deserialize(parameter.getValue(), parameterType.clazz());
        }
        properties.put(parameterType, object);
      }
    }

    return JsonRpcResponse.result(id, properties);
  }
コード例 #7
0
  /**
   * Deserializes the given element.
   *
   * @param element The JSON element to deserialize.
   * @param type The type to deserialize into.
   * @param context The context.
   * @return The deserialized object.
   * @throws JsonParseException
   */
  public Movie deserialize(JsonElement element, Type type, JsonDeserializationContext context)
      throws JsonParseException {
    JsonObject object = element.getAsJsonObject();

    ISerializer serializer = getSerializer();

    Movie movie = new Movie();

    element = object.get("id");
    movie.setID(element == null ? "" : element.getAsString());

    element = object.get("name");
    movie.setName(element == null ? "" : element.getAsString());

    element = object.get("year");
    movie.setYear(element == null ? 0 : element.getAsInt());

    element = object.get("synopsis");
    movie.setSynopsis(element == null ? "" : element.getAsString());

    element = object.get("genres");
    for (JsonElement current : element.getAsJsonArray())
      movie.getGenres().add(context.<Genre>deserialize(current, Genre.class));

    element = object.get("addDate");
    movie.setAddDate(
        element == null
            ? new Date(1970, 1, 1)
            : serializer.deserialize(element.getAsString(), Date.class));

    element = object.get("lastWatched");
    movie.setLastWatched(
        element == null ? new User() : context.<User>deserialize(element, User.class));

    element = object.get("lastWatchedDate");
    movie.setLastWatchedDate(new Date(1970, 1, 1));
    if (!element.isJsonNull())
      movie.setLastWatchedDate(serializer.deserialize(element.getAsString(), Date.class));

    element = object.get("poster");
    movie.setPoster(element == null ? "" : element.getAsString());

    element = object.get("director");
    movie.setDirector(element == null ? "" : element.getAsString());

    element = object.get("actors");
    for (JsonElement current : element.getAsJsonArray())
      movie.getActors().add(current.getAsString());

    element = object.get("file");
    movie.setFile(element == null ? "" : element.getAsString());

    element = object.get("encoded");
    movie.isEncoded(element != null && element.getAsBoolean());

    element = object.get("url");
    movie.setUrl(element == null ? "" : element.getAsString());

    return movie;
  }
コード例 #8
0
 @Override
 public JvmOptions deserialize(JsonElement json, Type type, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObj = json.getAsJsonObject();
   String extraOptions = context.deserialize(jsonObj.get("extraOptions"), String.class);
   JvmOptions.DebugOptions debugOptions =
       context.deserialize(jsonObj.get("debugOptions"), JvmOptions.DebugOptions.class);
   return new JvmOptions(extraOptions, debugOptions);
 }
コード例 #9
0
 @Override
 public Description deserialize(
     JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObj = json.getAsJsonObject();
   if (jsonObj.has("locations") || jsonObj.has("broadcasts")) {
     return context.deserialize(json, Item.class);
   } else {
     return context.deserialize(json, Playlist.class);
   }
 }
コード例 #10
0
  protected void deserialize(
      @Nonnull JsonObject object,
      @Nonnull BaseComponent component,
      @Nonnull JsonDeserializationContext context) {
    if (object.has("color")) {
      component.setColor(ChatColor.valueOf(object.get("color").getAsString().toUpperCase()));
    }
    if (object.has("bold")) {
      component.setBold(object.get("bold").getAsBoolean());
    }
    if (object.has("italic")) {
      component.setItalic(object.get("italic").getAsBoolean());
    }
    if (object.has("underlined")) {
      component.setUnderlined(object.get("underlined").getAsBoolean());
    }
    if (object.has("strikethrough")) {
      component.setUnderlined(object.get("strikethrough").getAsBoolean());
    }
    if (object.has("obfuscated")) {
      component.setUnderlined(object.get("obfuscated").getAsBoolean());
    }
    if (object.has("extra")) {
      component.setExtra(
          Arrays.asList(
              context.<BaseComponent[]>deserialize(object.get("extra"), BaseComponent[].class)));
    }

    // Events
    if (object.has("clickEvent")) {
      JsonObject event = object.getAsJsonObject("clickEvent");
      component.setClickEvent(
          new ClickEvent(
              ClickEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()),
              event.get("value").getAsString()));
    }
    if (object.has("hoverEvent")) {
      JsonObject event = object.getAsJsonObject("hoverEvent");
      BaseComponent[] res;
      if (event.get("value").isJsonArray()) {
        res = context.deserialize(event.get("value"), BaseComponent[].class);
      } else {
        res =
            new BaseComponent[] {
              context.<BaseComponent>deserialize(event.get("value"), BaseComponent.class)
            };
      }
      component.setHoverEvent(
          new HoverEvent(
              HoverEvent.Action.valueOf(event.get("action").getAsString().toUpperCase()), res));
    }
  }
コード例 #11
0
ファイル: Segment.java プロジェクト: GameModsBR/MyTown2
 private <T> List<T> deserializeAsArray(
     JsonElement json,
     JsonDeserializationContext context,
     TypeToken<T> typeToken,
     Type listOfT) {
   if (json.isJsonPrimitive()) {
     List<T> list = new ArrayList<T>();
     list.add((T) context.deserialize(json, typeToken.getType()));
     return list;
   } else {
     return context.deserialize(json, listOfT);
   }
 }
コード例 #12
0
  @Override
  public RemoteClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {

    JsonObject object = (JsonObject) json;

    String name = null;
    Doc doc = null;
    boolean abstractValue = false;
    TypeRef extendsValue = null;
    List<Method> constructors = new ArrayList<Method>();
    List<Method> methods = new ArrayList<Method>();
    List<TypeRef> events = new ArrayList<TypeRef>();

    if (object.get("name") != null) {
      name = object.get("name").getAsString();
    }

    if (object.get("doc") != null) {
      doc = new Doc(object.get("doc").getAsString());
    }

    if (object.get("abstract") != null) {
      abstractValue = object.get("abstract").getAsBoolean();
    }

    if (object.get("extends") != null) {
      extendsValue = context.deserialize(object.get("extends"), TypeRef.class);
    }

    if (object.get("constructors") != null) {
      constructors =
          context.deserialize(
              object.get("constructors"), new TypeToken<List<Method>>() {}.getType());
    }

    if (object.get("methods") != null) {
      methods =
          context.deserialize(object.get("methods"), new TypeToken<List<Method>>() {}.getType());
    }

    if (object.get("events") != null) {
      events =
          context.deserialize(object.get("events"), new TypeToken<List<TypeRef>>() {}.getType());
    }

    RemoteClass remoteClass =
        new RemoteClass(name, doc, extendsValue, constructors, methods, events);
    remoteClass.setAbstract(abstractValue);
    return remoteClass;
  }
コード例 #13
0
ファイル: BlockLoader.java プロジェクト: aaronb/Terasology
 public static <T> void deserializeBlockPartMap(
     EnumMap<BlockPart, T> target,
     JsonObject jsonObj,
     Class<T> type,
     JsonDeserializationContext context) {
   if (jsonObj.has("all")) {
     T value = context.deserialize(jsonObj.get("all"), type);
     for (BlockPart part : BlockPart.values()) {
       target.put(part, value);
     }
   }
   if (jsonObj.has("sides")) {
     T value = context.deserialize(jsonObj.get("sides"), type);
     for (Side side : Side.horizontalSides()) {
       target.put(BlockPart.fromSide(side), value);
     }
   }
   if (jsonObj.has("topBottom")) {
     T value = context.deserialize(jsonObj.get("topBottom"), type);
     target.put(BlockPart.TOP, value);
     target.put(BlockPart.BOTTOM, value);
   }
   if (jsonObj.has("top")) {
     T value = context.deserialize(jsonObj.get("top"), type);
     target.put(BlockPart.TOP, value);
   }
   if (jsonObj.has("bottom")) {
     T value = context.deserialize(jsonObj.get("bottom"), type);
     target.put(BlockPart.BOTTOM, value);
   }
   if (jsonObj.has("front")) {
     T value = context.deserialize(jsonObj.get("front"), type);
     target.put(BlockPart.FRONT, value);
   }
   if (jsonObj.has("back")) {
     T value = context.deserialize(jsonObj.get("back"), type);
     target.put(BlockPart.BACK, value);
   }
   if (jsonObj.has("left")) {
     T value = context.deserialize(jsonObj.get("left"), type);
     target.put(BlockPart.LEFT, value);
   }
   if (jsonObj.has("right")) {
     T value = context.deserialize(jsonObj.get("right"), type);
     target.put(BlockPart.RIGHT, value);
   }
   if (jsonObj.has("center")) {
     T value = context.deserialize(jsonObj.get("center"), type);
     target.put(BlockPart.CENTER, value);
   }
 }
コード例 #14
0
 @Override
 public JvmOptions.DebugOptions deserialize(
     JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObj = json.getAsJsonObject();
   Boolean doDebug = context.deserialize(jsonObj.get("doDebug"), Boolean.class);
   if (!doDebug) {
     return JvmOptions.DebugOptions.NO_DEBUG;
   }
   Boolean doSuspend = context.deserialize(jsonObj.get("doSuspend"), Boolean.class);
   Set<String> runnables =
       context.deserialize(jsonObj.get("runnables"), new TypeToken<Set<String>>() {}.getType());
   return new JvmOptions.DebugOptions(
       true, doSuspend, runnables == null ? null : ImmutableSet.copyOf(runnables));
 }
コード例 #15
0
 @Override
 public Project deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   return Project.builder()
       .fromProject((Project) context.deserialize(json, ProjectInternal.class))
       .build();
 }
コード例 #16
0
 @Override
 public TargetInfo deserialize(
     JsonElement element, Type type, final JsonDeserializationContext context)
     throws JsonParseException {
   final JsonObject object = element.getAsJsonObject();
   final List<String> targets = getStringListField(object, "targets");
   final List<String> libraries = getStringListField(object, "libraries");
   final List<String> excludes = getStringListField(object, "excludes");
   final List<SourceRoot> sourceRoots =
       getFieldAsList(
           object.getAsJsonArray("roots"),
           new Function<JsonElement, SourceRoot>() {
             @Override
             public SourceRoot fun(JsonElement element) {
               return context.deserialize(element, SourceRoot.class);
             }
           });
   final TargetAddressInfo addressInfo = context.deserialize(element, TargetAddressInfo.class);
   return new TargetInfo(
       new HashSet<TargetAddressInfo>(Collections.singleton(addressInfo)),
       new HashSet<String>(targets),
       new HashSet<String>(libraries),
       new HashSet<String>(excludes),
       new HashSet<SourceRoot>(sourceRoots));
 }
コード例 #17
0
ファイル: NovaParserModule.java プロジェクト: kwart/jclouds
 @Override
 public HostResourceUsage deserialize(
     JsonElement jsonElement, Type type, JsonDeserializationContext context)
     throws JsonParseException {
   return apply(
       (HostResourceUsageView) context.deserialize(jsonElement, HostResourceUsageView.class));
 }
コード例 #18
0
ファイル: Segment.java プロジェクト: GameModsBR/MyTown2
    private SegmentBlock deserializeBlock(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }
      SegmentBlock segment = new SegmentBlock();
      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<BlockType>() {},
              new TypeToken<List<BlockType>>() {}.getType()));
      json.remove("actions");

      if (json.has("meta")) {
        segment.meta = json.get("meta").getAsInt();
        json.remove("meta");
      }

      if (json.has("clientUpdate")) {
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume)
                    context.deserialize(
                        json.get("clientUpdate").getAsJsonObject().get("coords"), Volume.class));
        json.remove("clientUpdate");
      }

      return segment;
    }
コード例 #19
0
  @Override
  public Rating deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
    Integer value = context.deserialize(json, Integer.class);

    return new Rating(value);
  }
コード例 #20
0
    @Override
    public VersionObject deserialize(
        JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
      VersionObject obj = new VersionObject();
      obj.artifacts = new LinkedList<Artifact>();

      JsonObject groupLevel = json.getAsJsonObject().getAsJsonObject("artefacts");

      // itterate over the groups
      for (Entry<String, JsonElement> groupE : groupLevel.entrySet()) {
        String group = groupE.getKey();

        // itterate over the artefacts in the groups
        for (Entry<String, JsonElement> artifactE :
            groupE.getValue().getAsJsonObject().entrySet()) {
          Artifact artifact = context.deserialize(artifactE.getValue(), Artifact.class);
          artifact.group = group;

          if ("latest".equals(artifactE.getKey())) {
            obj.latest = artifact;
          } else {
            obj.artifacts.add(artifact);
          }
        }
      }

      return obj;
    }
 @Override
 public ModulePart deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObject = json.getAsJsonObject();
   if (!jsonObject.has("type")) {
     return ParseUtil.throwIfDebug("Invalid module part");
   }
   String type = jsonObject.get("type").getAsString();
   switch (type) {
     case "figure-group":
       return context.deserialize(json, FigureGroup.class);
     case "module-body":
       return context.deserialize(json, ModuleBody.class);
     default:
       return ParseUtil.throwIfDebug("Unrecognized ModulePart with type: " + type);
   }
 }
コード例 #22
0
 @Override
 public AssetReference deserialize(JsonElement j, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject json = j.getAsJsonObject().get("asset").getAsJsonObject();
   AssetReference asset = new AssetReference();
   asset.asset = context.deserialize(json, GsonUtils.readClassProperty(json, context));
   return asset;
 }
コード例 #23
0
  public ArrayOfIdentity deserialize(JsonElement json, Type t, JsonDeserializationContext context)
      throws JsonParseException {
    ArrayOfIdentity toReturn = new ArrayOfIdentity();
    Type deserialisationType = new TypeToken<ArrayList<IdentityImpl>>() {}.getType();
    toReturn.setIdentities((List<IdentityImpl>) context.deserialize(json, deserialisationType));

    return toReturn;
  }
コード例 #24
0
 /**
  * This allows for the deserialization of objects that use an interface in order to retain
  * information of the implementing object.
  *
  * @return Returns the actual implementing object, with memory of its type.
  */
 public T deserialize(JsonElement elem, Type interfaceType, JsonDeserializationContext context)
     throws JsonParseException {
   final JsonObject wrapper = (JsonObject) elem;
   final JsonElement typeName = get(wrapper, "type");
   final JsonElement data = get(wrapper, "data");
   final Type actualType = typeForName(typeName);
   return context.deserialize(data, actualType);
 }
コード例 #25
0
ファイル: HalDeserializer.java プロジェクト: bbil/halarious
 /**
  * Schreibt eine Referenz in einen einfachen String
  *
  * @param result Hal-Resource, in welcher sich die Referenz befindet
  * @param field Zu schreibendes Feld
  * @param jsonField JSON-Feld, welches die Referenz enthält
  * @param context GSON-Context für die Deserialisierung
  */
 private void writeLinkInString(
     HalResource result, Field field, JsonElement jsonField, JsonDeserializationContext context) {
   // Wir haben ein einzelne Objekt, das wir nun Deserialisieren
   HalReference halRef = context.deserialize(jsonField, HalReference.class);
   // Wert schreiben
   String href = halRef.getHref();
   HalReflectionHelper.setValue(result, field, href);
 }
コード例 #26
0
ファイル: HalDeserializer.java プロジェクト: bbil/halarious
  /**
   * Schreibt eine Referenz in eine Collection aus {@link HalReference}s
   *
   * @param collection Collection, in welche die Referenz geschrieben werden soll
   * @param element JSON-Element mit der Referenz
   * @param context GSON-Context für die Deserialisierung
   */
  protected void writeLinkInCollection(
      Collection collection, JsonElement element, JsonDeserializationContext context) {
    // Wir haben ein einzelne Objekt, das wir nun Deserialisieren
    HalReference halRef = context.deserialize(element, HalReference.class);

    // In die Liste einfügen
    collection.add(halRef);
  }
コード例 #27
0
 @Override
 public Operation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   Operation.Builder operationBuilder =
       ((Operation) context.deserialize(json, OperationInternal.class)).toBuilder();
   JsonObject error = json.getAsJsonObject().getAsJsonObject("error");
   if (error != null) {
     JsonArray array = error.getAsJsonArray("errors");
     if (array != null) {
       for (JsonElement element : array) {
         operationBuilder.addError(
             (Operation.Error) context.deserialize(element, Operation.Error.class));
       }
     }
   }
   return operationBuilder.build();
 }
コード例 #28
0
  @Override
  public BICitsmartResp deserialize(
      JsonElement json, Type typeOfT, JsonDeserializationContext context)
      throws JsonParseException {
    BICitsmartResp resp = new BICitsmartResp();

    BigInteger operationId = null;
    String xml = null;
    CtError error = null;
    XMLGregorianCalendar dateTime = null;

    JsonObject jsonObject = json.getAsJsonObject();

    if (!(jsonObject.get("operationID") instanceof JsonNull)) {
      operationId = jsonObject.get("operationID").getAsBigInteger();
    }

    if (!(jsonObject.get("xml") instanceof JsonNull)) {
      xml = jsonObject.get("xml").getAsString();
    }

    if (!(jsonObject.get("error") instanceof JsonNull)) {
      error = context.deserialize(jsonObject.get("error"), CtError.class);
    }

    if (!(jsonObject.get("dateTime") instanceof JsonNull)) {
      try {
        GregorianCalendar gc = new GregorianCalendar();

        long dt = jsonObject.get("dateTime").getAsLong();
        gc.setTimeInMillis(dt);

        dateTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
      } catch (DatatypeConfigurationException e) {

        e.printStackTrace();
      }
    }

    resp.setDateTime(dateTime);
    resp.setOperationID(operationId);
    resp.setError(error);
    resp.setXml(xml);

    return resp;

    /*
    {
        "dateTime":1412859455000,
        "operationID":null,
        "error":{
            "code":"PARAM",
            "description":"Usuário não tem acesso à operação"
        },
        "xml":null
    }
     */
  }
コード例 #29
0
 @Override
 public Cube deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   if (json.isJsonObject()) {
     MiniCube cube = context.deserialize(json, MiniCube.class);
     return cube;
   }
   return null;
 }
コード例 #30
0
ファイル: CreateTable.java プロジェクト: combineads/tajo
 @Override
 public PartitionMethodDescExpr deserialize(
     JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   JsonObject jsonObject = json.getAsJsonObject();
   PartitionType type =
       PartitionType.valueOf(
           CommonGsonHelper.getOrDie(jsonObject, "PartitionType").getAsString());
   switch (type) {
     case RANGE:
       return context.deserialize(json, RangePartition.class);
     case HASH:
       return context.deserialize(json, HashPartition.class);
     case LIST:
       return context.deserialize(json, ListPartition.class);
     case COLUMN:
       return context.deserialize(json, ColumnPartition.class);
   }
   return null;
 }