Java Code Examples for com.google.gson.JsonParseException

The following are top voted examples for showing how to use com.google.gson.JsonParseException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Ghost-Android   File: DateDeserializer.java   View source code 7 votes vote down vote up
@Override
public Date deserialize(JsonElement element, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    String date = element.getAsString();

    @SuppressLint("SimpleDateFormat")
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    try {
        return formatter.parse(date);
    } catch (ParseException e) {
        Log.e(TAG, "Date parsing failed");
        Log.exception(e);
        return new Date();
    }
}
 
Example 2
Project: ja-micro   File: ProtobufUtil.java   View source code 6 votes vote down vote up
private static boolean isValidJSON(String input) {
    if (StringUtils.isBlank(input)) {
        logger.warn("Parsing empty json string to protobuf is deprecated and will be removed in " +
                "the next major release");
        return false;
    }

    if (!input.startsWith("{")) {
        logger.warn("Parsing json string that does not start with { is deprecated and will be " +
                "removed in the next major release");
        return false;
    }

    try {
        new JsonParser().parse(input);
    } catch (JsonParseException ex) {
        return false;
    }

    return true;
}
 
Example 3
Project: BittrexApi   File: DefaultDateTypeAdapter.java   View source code 6 votes vote down vote up
@Override
public Date read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }

    if (in.peek() != JsonToken.STRING) {
        throw new JsonParseException("The date should be a string value");
    }

    Date date = deserializeToDate(in.nextString());

    if (dateType == Date.class) {
        return date;
    } else if (dateType == Timestamp.class) {
        return new Timestamp(date.getTime());
    } else if (dateType == java.sql.Date.class) {
        return new java.sql.Date(date.getTime());
    } else {
        // This must never happen: dateType is guarded in the primary constructor
        throw new AssertionError();
    }
}
 
Example 4
Project: boohee_v5.6   File: Streams.java   View source code 6 votes vote down vote up
public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try {
        reader.peek();
        isEmpty = false;
        return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (Throwable e) {
        if (isEmpty) {
            return JsonNull.INSTANCE;
        }
        throw new JsonSyntaxException(e);
    } catch (Throwable e2) {
        throw new JsonSyntaxException(e2);
    } catch (Throwable e22) {
        throw new JsonIOException(e22);
    } catch (Throwable e222) {
        throw new JsonSyntaxException(e222);
    }
}
 
Example 5
Project: Phoenix-for-VK   File: AttachmentsDtoAdapter.java   View source code 6 votes vote down vote up
@Override
public VkApiAttachments deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray array = json.getAsJsonArray();
    VkApiAttachments dto = new VkApiAttachments();

    dto.entries = new ArrayList<>(array.size());
    for(int i = 0; i < array.size(); i++){
        JsonObject o = array.get(i).getAsJsonObject();

        String type = optString(o, "type");
        VKApiAttachment attachment = parse(type, o, context);

        if(Objects.nonNull(attachment)){
            dto.entries.add(new VkApiAttachments.Entry(type, attachment));
        }
    }

    return dto;
}
 
Example 6
Project: CustomWorldGen   File: ForgeBlockStateV1.java   View source code 6 votes vote down vote up
public static Matrix4f parseMatrix(JsonElement e)
{
    if (!e.isJsonArray()) throw new JsonParseException("Matrix: expected an array, got: " + e);
    JsonArray m = e.getAsJsonArray();
    if (m.size() != 3) throw new JsonParseException("Matrix: expected an array of length 3, got: " + m.size());
    Matrix4f ret = new Matrix4f();
    for (int i = 0; i < 3; i++)
    {
        if (!m.get(i).isJsonArray()) throw new JsonParseException("Matrix row: expected an array, got: " + m.get(i));
        JsonArray r = m.get(i).getAsJsonArray();
        if (r.size() != 4) throw new JsonParseException("Matrix row: expected an array of length 4, got: " + r.size());
        for (int j = 0; j < 4; j++)
        {
            try
            {
                ret.setElement(i, j, r.get(j).getAsNumber().floatValue());
            }
            catch (ClassCastException ex)
            {
                throw new JsonParseException("Matrix element: expected number, got: " + r.get(j));
            }
        }
    }
    return ret;
}
 
Example 7
Project: OSchina_resources_android   File: ImageJsonDeserializer.java   View source code 6 votes vote down vote up
@Override
public Tweet.Image deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        if (json.isJsonObject()) {
            Tweet.Image image = new Tweet.Image();
            // The whole object is available
            final JsonObject jsonObject = json.getAsJsonObject();
            image.setThumb(context.<String>deserialize(jsonObject.get("thumb"), String.class));
            image.setHref(context.<String>deserialize(jsonObject.get("href"), String.class));
            image.setH(context.<Integer>deserialize(jsonObject.get("h"), int.class));
            image.setW(context.<Integer>deserialize(jsonObject.get("w"), int.class));
            if (Tweet.Image.check(image))
                return image;
            else
                return null;
        }
    } catch (Exception e) {
        TLog.error("ImageJsonDeserializer-deserialize-error:" + (json != null ? json.toString() : ""));
    }
    return null;
}
 
Example 8
Project: ObsidianSuite   File: JsonModel.java   View source code 6 votes vote down vote up
@Override
public JsonJsonModel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException
{
    JsonObject jsonObject = json.getAsJsonObject();
    JsonJsonModel model = JsonFactory.getGson().fromJson(json, JsonJsonModel.class);
    for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet())
    {
        if (entry.getKey().equals("textures"))
        {
            Map<String, String> map = context.deserialize(entry.getValue(), Map.class);
            for (String o : map.keySet())
            {
                model.texMap.put(o, map.get(o));
            }
        }
    }
    return model;
}
 
Example 9
Project: DecompiledMinecraft   File: BlockPart.java   View source code 6 votes vote down vote up
public BlockPart deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    Vector3f vector3f = this.parsePositionFrom(jsonobject);
    Vector3f vector3f1 = this.parsePositionTo(jsonobject);
    BlockPartRotation blockpartrotation = this.parseRotation(jsonobject);
    Map<EnumFacing, BlockPartFace> map = this.parseFacesCheck(p_deserialize_3_, jsonobject);

    if (jsonobject.has("shade") && !JsonUtils.isBoolean(jsonobject, "shade"))
    {
        throw new JsonParseException("Expected shade to be a Boolean");
    }
    else
    {
        boolean flag = JsonUtils.getBoolean(jsonobject, "shade", true);
        return new BlockPart(vector3f, vector3f1, map, blockpartrotation, flag);
    }
}
 
Example 10
Project: arquillian-reporter   File: EntryJsonDeserializer.java   View source code 6 votes vote down vote up
@Override
public Entry deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext)
    throws JsonParseException {
    JsonObject jsonEntry = (JsonObject) json;

    JsonElement key = jsonEntry.get("key");
    JsonElement content = jsonEntry.get("content");
    JsonElement filePath = jsonEntry.get("filePath");

    if (key != null) {
        StringKey keyEntry = prepareGsonParser().fromJson(key, StringKey.class);
        JsonElement value = jsonEntry.get("value");
        if (value != null) {
            return new KeyValueEntry(keyEntry, prepareGsonParser().fromJson(value, Entry.class));
        }
    } else if (content != null) {
        StringKey stringEntry = prepareGsonParser().fromJson(content, StringKey.class);
        return new StringEntry(stringEntry);
    } else if (filePath != null) {
        String fileEntry = prepareGsonParser().fromJson(filePath, String.class);
        return new FileEntry(fileEntry);
    }

    return new StringEntry("");
}
 
Example 11
Project: buckaroo   File: ProjectSerializerTest.java   View source code 6 votes vote down vote up
@org.junit.Test
public void testProjectSerializer1() throws Exception {

    final Project project = Project.of(
        Optional.of("my-magic-tool"),
        Optional.of("my-magic-tool-lib"),
        Optional.of("MIT"),
        DependencyGroup.of(ImmutableMap.of(
            RecipeIdentifier.of("org", "my-magic-lib"),
            ExactSemanticVersion.of(SemanticVersion.of(4, 5, 6)),
            RecipeIdentifier.of("org", "some-other-lib"),
            ExactSemanticVersion.of(
                SemanticVersion.of(4, 1),
                SemanticVersion.of(4, 2)),
            RecipeIdentifier.of("org", "awesome-lib"),
            AnySemanticVersion.of())));

    final String serializedProject = Serializers.serialize(project);

    final Either<JsonParseException, Project> deserializedProject =
            Serializers.parseProject(serializedProject);

    assertEquals(Either.right(project), deserializedProject);
}
 
Example 12
Project: open-rmbt   File: ServerOption.java   View source code 5 votes vote down vote up
@Override
public ServerOption deserialize(JsonElement json, Type arg1,
		JsonDeserializationContext arg2) throws JsonParseException {
	Gson gson = new Gson();
	final ServerOption item = gson.fromJson(json, ServerOption.class);
	setParentRecursive(item, null);			
	return item;
}
 
Example 13
Project: DecompiledMinecraft   File: PlayerProfileCache.java   View source code 5 votes vote down vote up
/**
 * Load the cached profiles from disk
 */
public void load()
{
    BufferedReader bufferedreader = null;

    try
    {
        bufferedreader = Files.newReader(this.usercacheFile, Charsets.UTF_8);
        List<PlayerProfileCache.ProfileEntry> list = (List)this.gson.fromJson((Reader)bufferedreader, TYPE);
        this.usernameToProfileEntryMap.clear();
        this.uuidToProfileEntryMap.clear();
        this.gameProfiles.clear();

        for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
        {
            if (playerprofilecache$profileentry != null)
            {
                this.addEntry(playerprofilecache$profileentry.getGameProfile(), playerprofilecache$profileentry.getExpirationDate());
            }
        }
    }
    catch (FileNotFoundException var9)
    {
        ;
    }
    catch (JsonParseException var10)
    {
        ;
    }
    finally
    {
        IOUtils.closeQuietly((Reader)bufferedreader);
    }
}
 
Example 14
Project: DecompiledMinecraft   File: PackMetadataSectionSerializer.java   View source code 5 votes vote down vote up
public PackMetadataSection deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    IChatComponent ichatcomponent = (IChatComponent)p_deserialize_3_.deserialize(jsonobject.get("description"), IChatComponent.class);

    if (ichatcomponent == null)
    {
        throw new JsonParseException("Invalid/missing description!");
    }
    else
    {
        int i = JsonUtils.getInt(jsonobject, "pack_format");
        return new PackMetadataSection(ichatcomponent, i);
    }
}
 
Example 15
Project: GitHub   File: ExceptionEngine.java   View source code 5 votes vote down vote up
public static ApiException handleException(Throwable e) {
    ApiException ex;
    if (e instanceof HttpException) {             //HTTP错误
        HttpException httpExc = (HttpException) e;
        ex = new ApiException(e, httpExc.code());
        ex.setMsg("网络错误");  //均视为网络错误
        return ex;
    } else if (e instanceof ServerException) {    //服务器返回的错误
        ServerException serverExc = (ServerException) e;
        ex = new ApiException(serverExc, serverExc.getCode());
        ex.setMsg(serverExc.getMsg());
        return ex;
    } else if (e instanceof JsonParseException
            || e instanceof JSONException
            || e instanceof ParseException || e instanceof MalformedJsonException) {  //解析数据错误
        ex = new ApiException(e, ANALYTIC_SERVER_DATA_ERROR);
        ex.setMsg("解析错误");
        return ex;
    } else if (e instanceof ConnectException) {//连接网络错误
        ex = new ApiException(e, CONNECT_ERROR);
        ex.setMsg("连接失败");
        return ex;
    } else if (e instanceof SocketTimeoutException) {//网络超时
        ex = new ApiException(e, TIME_OUT_ERROR);
        ex.setMsg("网络超时");
        return ex;
    } else {  //未知错误
        ex = new ApiException(e, UN_KNOWN_ERROR);
        ex.setMsg("未知错误");
        return ex;
    }
}
 
Example 16
Project: GitHub   File: HolderJsonSerializer.java   View source code 5 votes vote down vote up
@Override
public Holder deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
  JsonObject root = (JsonObject) json;

  ImmutableHolder.Builder builder = ImmutableHolder.builder();

  if (root.has("id")) {
    builder.id(root.get("id").getAsString());
  }

  JsonElement value = root.get(VALUE_PROPERTY);
  if (value == null) {
    throw new JsonParseException(String.format("%s not found for %s in JSON", VALUE_PROPERTY, type));
  }

  if (value.isJsonObject()) {
    final String valueTypeName = value.getAsJsonObject().get(Holder.TYPE_PROPERTY).getAsString();
    try {
      Class<?> valueType = Class.forName(valueTypeName);
      builder.value(context.deserialize(value, valueType));
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(String.format("Couldn't construct value class %s for %s", valueTypeName, type), e);
    }
  } else if (value.isJsonPrimitive()) {
    final JsonPrimitive primitive = value.getAsJsonPrimitive();
    if (primitive.isString()) {
      builder.value(primitive.getAsString());
    } else if (primitive.isNumber()) {
      builder.value(primitive.getAsInt());
    } else if (primitive.isBoolean()) {
      builder.value(primitive.getAsBoolean());
    }
  } else {
    throw new JsonParseException(
        String.format("Couldn't deserialize %s : %s. Not a primitive or object", VALUE_PROPERTY, value));
  }

  return builder.build();

}
 
Example 17
Project: Clases-2017c1   File: EventAdapter.java   View source code 5 votes vote down vote up
@Override
public Event deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject =  json.getAsJsonObject();
    if (jsonObject.get("reply_to") != null) {
        return context.deserialize(json, ResponseEvent.class);
    }
    JsonElement typeObj = jsonObject.get("type");
    String type = typeObj != null ? typeObj.getAsString() : null;
    Class<? extends Event> clazz = classForType(type != null ? type : "unknown");
    return context.deserialize(json, clazz);
}
 
Example 18
Project: bullet-core   File: AbstractQuery.java   View source code 5 votes vote down vote up
/**
 * Constructor that takes a String representation of the query and a configuration to use.
 *
 * @param queryString The query as a string.
 * @param config The validated {@link BulletConfig} configuration to use.
 * @throws ParsingException if there was an issue.
 */
public AbstractQuery(String queryString, BulletConfig config) throws JsonParseException, ParsingException {
    this.queryString = queryString;
    specification = Parser.parse(queryString, config);
    Optional<List<Error>> errors = specification.validate();
    if (errors.isPresent()) {
        throw new ParsingException(errors.get());
    }
    duration = specification.getDuration();
    startTime = System.currentTimeMillis();
}
 
Example 19
Project: BaseClient   File: BlockPart.java   View source code 5 votes vote down vote up
private EnumFacing.Axis parseAxis(JsonObject p_178252_1_)
{
    String s = JsonUtils.getString(p_178252_1_, "axis");
    EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.byName(s.toLowerCase());

    if (enumfacing$axis == null)
    {
        throw new JsonParseException("Invalid rotation axis: " + s);
    }
    else
    {
        return enumfacing$axis;
    }
}
 
Example 20
Project: nifi-swagger-client   File: JSON.java   View source code 5 votes vote down vote up
/**
 * Deserialize
 *
 * @param json Json element
 * @param date Type
 * @param context Json Serialization Context
 * @return Date
 * @throws JsonParseException if fail to parse
 */
@Override
public Date deserialize(JsonElement json, Type date, JsonDeserializationContext context) throws JsonParseException {
    String str = json.getAsJsonPrimitive().getAsString();
    try {
        return apiClient.parseDateOrDatetime(str);
    } catch (RuntimeException e) {
        throw new JsonParseException(e);
    }
}
 
Example 21
Project: gplaymusic   File: AutogenEnumDeserializer.java   View source code 5 votes vote down vote up
@Override
public ArtRef.Autogen deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
  if (json.getAsBoolean()) {
    return ArtRef.Autogen.TRUE;
  }
  return ArtRef.Autogen.FALSE;
}
 
Example 22
Project: iosched-reader   File: VendorDynamicInput.java   View source code 5 votes vote down vote up
private void checkPagingConsistency(InputJsonKeys.VendorAPISource.MainTypes entityType,
    int requestedPage, JsonObject obj) {
  if (!obj.has("page") || !obj.has("pagesize") || !obj.has("total") ||
      (!obj.has("results") && !obj.has("topics"))) {
    throw new JsonParseException("Invalid response from Vendor API when"
        + "paging "+entityType+" results. At least one of the required properties "
        + "(page, pagesize, total, results|topics) could not be found.");
  }
  int currentPage = obj.get("page").getAsInt();
  if (requestedPage>0 && requestedPage != currentPage) {
    throw new JsonParseException("Invalid response from Vendor API when"
        + "paging "+entityType+" results. Requested page "+requestedPage
        +" but got page "+currentPage);
  }
}
 
Example 23
Project: VISNode   File: NodeNetworkParser.java   View source code 5 votes vote down vote up
@Override
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 createBareGsonBuilder().create().fromJson(data, actualType);
}
 
Example 24
Project: Backmemed   File: PlayerItemParser.java   View source code 5 votes vote down vote up
private static void checkNull(Object p_checkNull_0_, String p_checkNull_1_)
{
    if (p_checkNull_0_ == null)
    {
        throw new JsonParseException(p_checkNull_1_);
    }
}
 
Example 25
Project: BaseClient   File: BlockFaceUV.java   View source code 5 votes vote down vote up
private float[] parseUV(JsonObject p_178292_1_)
{
    if (!p_178292_1_.has("uv"))
    {
        return null;
    }
    else
    {
        JsonArray jsonarray = JsonUtils.getJsonArray(p_178292_1_, "uv");

        if (jsonarray.size() != 4)
        {
            throw new JsonParseException("Expected 4 uv values, found: " + jsonarray.size());
        }
        else
        {
            float[] afloat = new float[4];

            for (int i = 0; i < afloat.length; ++i)
            {
                afloat[i] = JsonUtils.getFloat(jsonarray.get(i), "uv[" + i + "]");
            }

            return afloat;
        }
    }
}
 
Example 26
Project: buckaroo   File: Serializers.java   View source code 5 votes vote down vote up
private static <T> Either<JsonParseException, T> parse(final String x, final Class<T> clazz) {
    Preconditions.checkNotNull(x);
    Preconditions.checkNotNull(clazz);
    try {
        final T t = gson.fromJson(
                new EmptyStringFailFastJsonReader(new StringReader(x)), clazz);
        return Either.right(t);
    } catch (final JsonParseException e) {
        return Either.left(e);
    }
}
 
Example 27
Project: Regalia   File: RealmListGsonConverter.java   View source code 5 votes vote down vote up
@Override
public RealmList<T> deserialize(JsonElement json, Type typeOfT,
                                        JsonDeserializationContext context) throws JsonParseException {
    RealmList<T> items = new RealmList<>();
    JsonArray ja = json.getAsJsonArray();
    for (JsonElement je : ja) {
        items.add((T) context.deserialize(je, getObjectType()));
    }
    return items;
}
 
Example 28
Project: Backmemed   File: ItemTransformVec3f.java   View source code 5 votes vote down vote up
public ItemTransformVec3f deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    Vector3f vector3f = this.parseVector3f(jsonobject, "rotation", ROTATION_DEFAULT);
    Vector3f vector3f1 = this.parseVector3f(jsonobject, "translation", TRANSLATION_DEFAULT);
    vector3f1.scale(0.0625F);
    vector3f1.x = MathHelper.clamp(vector3f1.x, -5.0F, 5.0F);
    vector3f1.y = MathHelper.clamp(vector3f1.y, -5.0F, 5.0F);
    vector3f1.z = MathHelper.clamp(vector3f1.z, -5.0F, 5.0F);
    Vector3f vector3f2 = this.parseVector3f(jsonobject, "scale", SCALE_DEFAULT);
    vector3f2.x = MathHelper.clamp(vector3f2.x, -4.0F, 4.0F);
    vector3f2.y = MathHelper.clamp(vector3f2.y, -4.0F, 4.0F);
    vector3f2.z = MathHelper.clamp(vector3f2.z, -4.0F, 4.0F);
    return new ItemTransformVec3f(vector3f, vector3f1, vector3f2);
}
 
Example 29
Project: BaseClient   File: PlayerItemParser.java   View source code 5 votes vote down vote up
private static void checkNull(Object p_checkNull_0_, String p_checkNull_1_)
{
    if (p_checkNull_0_ == null)
    {
        throw new JsonParseException(p_checkNull_1_);
    }
}
 
Example 30
Project: DecompiledMinecraft   File: ItemCameraTransforms.java   View source code 5 votes vote down vote up
public ItemCameraTransforms deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
    ItemTransformVec3f itemtransformvec3f = this.func_181683_a(p_deserialize_3_, jsonobject, "thirdperson");
    ItemTransformVec3f itemtransformvec3f1 = this.func_181683_a(p_deserialize_3_, jsonobject, "firstperson");
    ItemTransformVec3f itemtransformvec3f2 = this.func_181683_a(p_deserialize_3_, jsonobject, "head");
    ItemTransformVec3f itemtransformvec3f3 = this.func_181683_a(p_deserialize_3_, jsonobject, "gui");
    ItemTransformVec3f itemtransformvec3f4 = this.func_181683_a(p_deserialize_3_, jsonobject, "ground");
    ItemTransformVec3f itemtransformvec3f5 = this.func_181683_a(p_deserialize_3_, jsonobject, "fixed");
    return new ItemCameraTransforms(itemtransformvec3f, itemtransformvec3f1, itemtransformvec3f2, itemtransformvec3f3, itemtransformvec3f4, itemtransformvec3f5);
}
 
Example 31
Project: arquillian-reporter   File: ReportJsonDeserializer.java   View source code 5 votes vote down vote up
@Override
public Report deserialize(JsonElement json, Type typeOfReport, JsonDeserializationContext context)
    throws JsonParseException {

    JsonObject jsonReport = (JsonObject) json;

    if (jsonReport.get("testSuiteReports") != null) {
        return parseExecutionReport(jsonReport, context);

    } else if (jsonReport.get("testClassReports") != null) {
        return parseTestSuiteReport(jsonReport);

    } else if (jsonReport.get("testMethodReports") != null) {
        return parseTestClassReport(jsonReport);

    } else if (jsonReport.get("startTime") != null) {
        return parseTestMethodReport(jsonReport);

    } else {
        Report report;
        if (typeOfReport.getTypeName().equals(ConfigurationReport.class.getTypeName())){
            report = new ConfigurationReport();
        } else if (typeOfReport.getTypeName().equals(FailureReport.class.getTypeName())){
            report = new FailureReport();
        } else {
            report = new BasicReport();
        }
        return setDefaultValues(report, jsonReport);
    }
}
 
Example 32
Project: Backmemed   File: BlockPart.java   View source code 5 votes vote down vote up
private Map<EnumFacing, BlockPartFace> parseFacesCheck(JsonDeserializationContext deserializationContext, JsonObject object)
{
    Map<EnumFacing, BlockPartFace> map = this.parseFaces(deserializationContext, object);

    if (map.isEmpty())
    {
        throw new JsonParseException("Expected between 1 and 6 unique faces, got 0");
    }
    else
    {
        return map;
    }
}
 
Example 33
Project: CustomWorldGen   File: BlockPart.java   View source code 5 votes vote down vote up
private Map<EnumFacing, BlockPartFace> parseFacesCheck(JsonDeserializationContext deserializationContext, JsonObject object)
{
    Map<EnumFacing, BlockPartFace> map = this.parseFaces(deserializationContext, object);

    if (map.isEmpty())
    {
        throw new JsonParseException("Expected between 1 and 6 unique faces, got 0");
    }
    else
    {
        return map;
    }
}
 
Example 34
Project: Uranium   File: TranslatableComponentSerializer.java   View source code 5 votes vote down vote up
@Override
public TranslatableComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    TranslatableComponent component = new TranslatableComponent();
    JsonObject object = json.getAsJsonObject();
    this.deserialize(object, component, context);
    component.setTranslate(object.get("translate").getAsString());
    if (object.has("with")) {
        component.setWith(Arrays.asList((BaseComponent[])context.deserialize(object.get("with"), BaseComponent[].class)));
    }
    return component;
}
 
Example 35
Project: hypertrack-live-android   File: DateDeserializer.java   View source code 5 votes vote down vote up
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    try {
        return json == null ? null : new Date(json.getAsLong());

    } catch (NumberFormatException e) {
        CrashlyticsWrapper.log(e);
        e.printStackTrace();

        return deserialize12HourDateFormatString(json.getAsString());
    }
}
 
Example 36
Project: rapid-io-android   File: RapidGsonConverter.java   View source code 5 votes vote down vote up
@Override
public synchronized Date deserialize(@NonNull JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
	try {
		return dateFormat.parse(jsonElement.getAsString());
	} catch(ParseException e) {
		throw new JsonParseException(e);
	}
}
 
Example 37
Project: CustomWorldGen   File: LootPool.java   View source code 5 votes vote down vote up
public LootPool deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
    JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "loot pool");
    String name = net.minecraftforge.common.ForgeHooks.readPoolName(jsonobject);
    LootEntry[] alootentry = (LootEntry[])JsonUtils.deserializeClass(jsonobject, "entries", p_deserialize_3_, LootEntry[].class);
    LootCondition[] alootcondition = (LootCondition[])JsonUtils.deserializeClass(jsonobject, "conditions", new LootCondition[0], p_deserialize_3_, LootCondition[].class);
    RandomValueRange randomvaluerange = (RandomValueRange)JsonUtils.deserializeClass(jsonobject, "rolls", p_deserialize_3_, RandomValueRange.class);
    RandomValueRange randomvaluerange1 = (RandomValueRange)JsonUtils.deserializeClass(jsonobject, "bonus_rolls", new RandomValueRange(0.0F, 0.0F), p_deserialize_3_, RandomValueRange.class);
    return new LootPool(alootentry, alootcondition, randomvaluerange, randomvaluerange1, name);
}
 
Example 38
Project: MVVMFrames   File: GsonResponseDeserializer.java   View source code 5 votes vote down vote up
@Override
public ResponseEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject response = json.getAsJsonObject();
    if (response.get("result").isJsonPrimitive()) {// 是否为基本数据类型
        int code = response.get("code").getAsInt();
        String message = response.get("info").getAsString();
        return new ResponseEntity(code, message);
    }

    return new Gson().fromJson(json, typeOfT);
}
 
Example 39
Project: Readhub-Android   File: EntityUtils.java   View source code 5 votes vote down vote up
@Override
public OffsetDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    String src = json.getAsString();
    // TODO 有些时间结构不符合标准,这里做兼容
    try {
        return OffsetDateTime.parse(src);
    } catch (DateTimeParseException e) {
        return OffsetDateTime.of(LocalDateTime.parse(src, formatterCompat), ZoneOffset.UTC);
    }
}
 
Example 40
Project: Backmemed   File: PlayerProfileCache.java   View source code 5 votes vote down vote up
/**
 * Load the cached profiles from disk
 */
public void load()
{
    BufferedReader bufferedreader = null;

    try
    {
        bufferedreader = Files.newReader(this.usercacheFile, Charsets.UTF_8);
        List<PlayerProfileCache.ProfileEntry> list = (List)this.gson.fromJson((Reader)bufferedreader, TYPE);
        this.usernameToProfileEntryMap.clear();
        this.uuidToProfileEntryMap.clear();
        this.gameProfiles.clear();

        if (list != null)
        {
            for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
            {
                if (playerprofilecache$profileentry != null)
                {
                    this.addEntry(playerprofilecache$profileentry.getGameProfile(), playerprofilecache$profileentry.getExpirationDate());
                }
            }
        }
    }
    catch (FileNotFoundException var9)
    {
        ;
    }
    catch (JsonParseException var10)
    {
        ;
    }
    finally
    {
        IOUtils.closeQuietly((Reader)bufferedreader);
    }
}