尝试获取BackBlaze授权令牌时出现错误。之前它运行良好,突然我开始收到此错误消息-
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "allowed" (class au.com.polonious.cloud.node.backblaze.BackBlazeTokenResponse), not marked as ignorable (7 known properties: "authorizationToken", "minimumPartSize", "apiUrl", "downloadUrl", "accountId", "absoluteMinimumPartSize", "recommendedPartSize"])
at [Source: {
"absoluteMinimumPartSize": 5000000,
"accountId": "b0c893f558bc",
"allowed": {
"bucketId": null,
"capabilities": [
"all"
],
"namePrefix": null
},
"apiUrl": "https://api001.backblazeb2.com",
"authorizationToken": "4_001b0c893f558bc0000000000_01851d94_6e8e3e_acct_yxmSYWYVETByLq8bwW8HMQSEjlM=",
"downloadUrl": "https://f001.backblazeb2.com",
"minimumPartSize": 100000000,
"recommendedPartSize": 100000000
}
; line: 4, column: 15] (through reference chain: au.com.polonious.cloud.node.backblaze.BackBlazeTokenResponse["allowed"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2858)
这是我的代码-
private BackBlazeTokenResponse getBackBlazeAuth(String accountId, String applicationKey)
throws Exception{
HttpURLConnection connection = null;
String headerForAuthorizeAccount = "Basic " + Base64.getEncoder().encodeToString((accountId + ":" + applicationKey).getBytes());
log.info("getBackBlaze Auth - headerForAuthorizeAccount - "+headerForAuthorizeAccount);
BackBlazeTokenResponse backBlazeTokenResponse = new BackBlazeTokenResponse();
String tokenJson="";
try {
URL url = new URL("https://api.backblazeb2.com/b2api/v1/b2_authorize_account");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", headerForAuthorizeAccount);
InputStream in = new BufferedInputStream(connection.getInputStream());
tokenJson = myInputStreamReader(in);
} catch (Exception e) {
e.printStackTrace();
} finally {
connection.disconnect();
//log.info("Output JSON:"+tokenJson);
ObjectMapper mapper = new ObjectMapper();
//JSON from file to Object
log.info("tokenJson- "+ tokenJson);
backBlazeTokenResponse = mapper.readValue(tokenJson, BackBlazeTokenResponse.class);
log.info("getAuthorizationToken:"+backBlazeTokenResponse.getAuthorizationToken());
return backBlazeTokenResponse;
}
}
此行中有错误-
backBlazeTokenResponse = mapper.readValue(tokenJson, BackBlazeTokenResponse.class);
不确定为什么突然开始引发此错误,可能是BackBlaze API中的某些更改。请帮忙。
答案 0 :(得分:0)
这解决了我的问题
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(JsonAutoDetect.Visibility.ANY));