当前位置: 首页>>代码示例>>Java>>正文


Java ConversionException类代码示例

本文整理汇总了Java中retrofit.converter.ConversionException的典型用法代码示例。如果您正苦于以下问题:Java ConversionException类的具体用法?Java ConversionException怎么用?Java ConversionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConversionException类属于retrofit.converter包,在下文中一共展示了ConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if(responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject)parser.parse(responseBodyString);
        JsonElement dataObject = element.get("data");
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:20,代码来源:CustomGsonConverter.java

示例2: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if (responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject) parser.parse(responseBodyString);
        JsonElement dataObject = null;
        if (element.has("items") && !(element.has("labels") && element.has("desc") && element.has("curl"))) {
            dataObject = element.get("items");
        } else {
            dataObject = element;
        }
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:26,代码来源:CustomGsonConverter.java

示例3: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    boolean willCloseStream = false; // try to close the stream, if there is no exception thrown
                                     // using tolerant JsonReader
    try {
        JsonReader jsonReader = new JsonReader(new InputStreamReader(body.in()));
        jsonReader.setLenient(true);
        Object o = mGson.fromJson(jsonReader, type);
        willCloseStream = true;
        return o;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (willCloseStream) {
            closeStream(body);
        }
    }

    return super.fromBody(body, type);
}
 
开发者ID:bwzz,项目名称:yyl,代码行数:21,代码来源:MyGsonConvertor.java

示例4: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        // Check if the type contains a parametrized list
        if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
            // Grab the actual type parameter from the parametrized list and delegate to LoganSquare
            ParameterizedType parameterized = (ParameterizedType) type;
            return LoganSquare.parseList(body.in(), (Class) parameterized.getActualTypeArguments()[0]);

        } else {
            // Single elements get parsed immediately
            return LoganSquare.parse(body.in(), (Class) type);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:getsadzeg,项目名称:AreYouAlive,代码行数:17,代码来源:LoganSquareConverter.java

示例5: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput typedInput, Type type) throws ConversionException {
    String text = null;
    try {
        typedInput.in();
        BufferedReader reader = new BufferedReader(new InputStreamReader(typedInput.in()));
        StringBuilder out = new StringBuilder();
        String newLine = System.getProperty("line.separator");
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
            out.append(newLine);
        }
        text = out.toString();
    } catch (IOException ignored) {/*NOP*/ }
    return text;
}
 
开发者ID:percolate,项目名称:foam,代码行数:18,代码来源:GoogleAnalytics.java

示例6: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput typedinput, Type type)
    throws ConversionException {
  if (typedinput.length() == 0L)
  {
    return null;
  }
  try
  {
    JavaType javaType = objectMapper.getTypeFactory().constructType(type);
    if (type.getClass().equals(Void.TYPE)) {
      return null;
    }
    return objectMapper.readValue(typedinput.in(), javaType);
  } catch (IOException e) {
    throw new ConversionException(e);
  }
}
 
开发者ID:offerHere,项目名称:offer,代码行数:19,代码来源:CustomJacksonConverter.java

示例7: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
	try {
		// Check if the type contains a parametrized list
		if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
			// Grab the actual type parameter from the parametrized list and delegate to LoganSquare
			ParameterizedType parameterized = (ParameterizedType) type;
			return LoganSquare.parseList(body.in(), (Class) parameterized.getActualTypeArguments()[0]);

		} else {
			// Single elements get parsed immediately
			return LoganSquare.parse(body.in(), (Class) type);
		}
	} catch (Exception e) {
		throw new ConversionException(e);
	}
}
 
开发者ID:yongjhih,项目名称:converter-logansquare-retrofit,代码行数:17,代码来源:LoganSquareConverter.java

示例8: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    String charset = "UTF-8";
    if (body.mimeType() != null) {
        charset = MimeUtil.parseCharset(body.mimeType());
    }
    InputStreamReader isr = null;
    try {
        isr = new InputStreamReader(body.in(), charset);
        return gson.fromJson(isr, type);
    } catch (IOException | JsonParseException e) {
        throw new ConversionException(e);
    } finally {
        if (isr != null) {
            try {
                isr.close();
            } catch (IOException ex) {
                // Ignored
            }
        }
    }
}
 
开发者ID:phil-lopreiato,项目名称:tba-apiv2-java,代码行数:23,代码来源:RetrofitConverter.java

示例9: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        // Check if the type contains a parametrized list
        if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
            // Grab the actual type parameter from the parametrized list and delegate to LoganSquare
            ParameterizedType parameterized = (ParameterizedType) type;
            return LoganSquare.parseList(body.in(), (Class) parameterized.getActualTypeArguments()[0]);

        } else {
            // Single elements get parsed immediately
            return LoganSquare.parse(body.in(), (Class) type);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:dinosaurwithakatana,项目名称:hacker-news-android,代码行数:18,代码来源:LoganSquareConvertor.java

示例10: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput typedInput, Type type) throws ConversionException {
    JavaType javaType = objectMapper.getTypeFactory().constructType(type);

    try {
        InputStream in = typedInput.in();
        try {
            return objectMapper.readValue(in, javaType);
        } finally {
             if (in != null) {
                 in.close();
             }
        }


    } catch (IOException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:AAverin,项目名称:android-skeleton-project,代码行数:20,代码来源:JacksonConverter.java

示例11: deserializes_product_from_feed

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Test
public void deserializes_product_from_feed() throws ConversionException {
    String feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:vidal=\"http://api.vidal.net/-/spec/vidal-api/1.0/\">" +
            "   <entry>" +
            "       <vidal:id>42</vidal:id>" +
            "       <title>Batman</title>" +
            "   </entry>" +
            "</feed>";

    Product product = deserializer.deserializeOne(feed);

    assertThat(product)
            .hasId("42")
            .hasName("Batman");
}
 
开发者ID:vidal-community,项目名称:vidal-api.java,代码行数:17,代码来源:ProductDeserializerTest.java

示例12: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    if (type != Token.class) {
        return mOriginalConverter.fromBody(body, type);
    }

    // We don't check for null refresh token, it's optional - it's retrieved on initial auth but not on a token refresh
    TokenResponse response = (TokenResponse) mOriginalConverter.fromBody(body,
            TokenResponse.class);
    if (response == null || response.getAccessToken() == null) {
        throw new ConversionException("Empty/missing token response: " + response);
    }
    return new Token.Builder().accessToken(response.getAccessToken())
            .refreshToken(response.getRefreshToken())
            .expiryTimeMillis(DateTime.now(DateTimeZone.UTC)
                    .plusSeconds(response.getExpiresIn())
                    .getMillis())
            .build();
}
 
开发者ID:emmaguy,项目名称:wear-notify-for-reddit,代码行数:19,代码来源:TokenConverter.java

示例13: fromBody

import retrofit.converter.ConversionException; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        Scanner s = new Scanner(body.in()).useDelimiter("\\A");
        String bodyText = s.hasNext() ? s.next() : "";

        boolean isSuccessResponse = bodyText.startsWith("202 Accepted");

        MarkAllRead markAllRead = new MarkAllRead();
        if (!isSuccessResponse) {
            markAllRead.setErrors(bodyText);
        }

        return markAllRead;
    } catch (IOException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:emmaguy,项目名称:wear-notify-for-reddit,代码行数:18,代码来源:MarkAsReadConverter.java

示例14: convertComments

import retrofit.converter.ConversionException; //导入依赖的package包/类
private List<Comment> convertComments(String filename) throws IOException, ConversionException {
    final TypedInput body = mock(TypedInput.class);
    when(body.in()).thenReturn(TestUtils.loadFileFromStream(filename));

    final CommentsConverter commentsConverter = new CommentsConverter(mGson,
            mGsonConverter,
            mResources,
            mUserStorage);
    final List<Comment> comments = (List<Comment>) commentsConverter.fromBody(body,
            new ParameterizedType() {
                @Override public Type[] getActualTypeArguments() {
                    return new Type[]{Comment.class};
                }

                @Override public Type getOwnerType() {
                    return null;
                }

                @Override public Type getRawType() {
                    return List.class;
                }
            });

    return comments;
}
 
开发者ID:emmaguy,项目名称:wear-notify-for-reddit,代码行数:26,代码来源:CommentsConverterTest.java

示例15: convertPostResponse

import retrofit.converter.ConversionException; //导入依赖的package包/类
private Post convertPostResponse(String filename) throws IOException, ConversionException {
    final TypedInput body = mock(TypedInput.class);
    when(body.in()).thenReturn(TestUtils.loadFileFromStream(filename));

    final PostConverter postConverter = new PostConverter(mGsonConverter,
            mResources,
            mUserStorage,
            mHtmlDecoder);
    final List<Post> posts = (List<Post>) postConverter.fromBody(body, new ParameterizedType() {
        @Override public Type[] getActualTypeArguments() {
            return new Type[]{Post.class};
        }

        @Override public Type getOwnerType() {
            return null;
        }

        @Override public Type getRawType() {
            return List.class;
        }
    });

    assertThat(posts.size(), equalTo(1));
    return posts.get(0);
}
 
开发者ID:emmaguy,项目名称:wear-notify-for-reddit,代码行数:26,代码来源:PostConverterTest.java


注:本文中的retrofit.converter.ConversionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。