使用gson解析json时,我有一种奇怪的行为.我用这个代码:
private static Container parseContainer(String containerJson) {
try {
//TODO Remove try catch when Bug is done
return containerJson != null ? new Gson().fromJson(containerJson, Container.class)
: null;
} catch (JsonSyntaxException e) {
LOGGER.error("JsonSyntaxException ", e);
LOGGER.error("Json: " + containerJson);
//Sleep 3 minutes and try again.
try {
Thread.sleep(1000L * 60 * 3);
} catch (InterruptedException e1) {
LOGGER.error("Exception", e);
}
LOGGER.error("Try again to parse json: " + containerJson);
Container result = new Gson().fromJson(containerJson, Container.class);
LOGGER.error("Parsing successful on second try.");
return …
Run Code Online (Sandbox Code Playgroud) 我使用商业API并且NullpointException
来自API代码.
支持告诉我它是预期的,因为我调用的方法的输入参数之一null
是使用methdod需要此参数.
这真的是我的错,因为在将参数传递给API之前我没有检查过参数吗?
放弃NullpointerExceptions
你的API 不是不好的做法吗?如果不是我必须检查所有类型,RuntimeExceptions
如果我使用该API的方法,如果我想确保我的软件不会崩溃.
如果是不好的做法,是否有任何文件或规格参考这个?