larksuite / larksuite/oapi-sdk-java
Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 310
- Forks
- 115
- PR merge metrics
- No merged PRs in 30d
Description
背景
需要将自研系统中的审批流数据同步到飞书审批中心。
资料
使用的SDK:com.larksuite.oapi:oapi-sdk:2.0.20
报错
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.Gson.fromJson(Gson.java:922)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:836)
at com.google.gson.Gson.fromJson(Gson.java:808)
at com.lark.oapi.core.utils.UnmarshalRespUtil.unmarshalResp(UnmarshalRespUtil.java:22)
at com.lark.oapi.service.approval.v4.ApprovalService$ExternalInstance.create(ApprovalService.java:587)
期望
先看代码
// 反序列化
CreateExternalInstanceResp resp = UnmarshalRespUtil.unmarshalResp(httpResponse, CreateExternalInstanceResp.class);
if (resp == null) {
log.error(String.format(
"%s,callError,req=%s,respHeader=%s,respStatusCode=%s,respBody=%s,", "/open-apis/approval/v4/external_instances"
, Jsons.DEFAULT.toJson(req), Jsons.DEFAULT.toJson(httpResponse.getHeaders()),
httpResponse.getStatusCode(), new String(httpResponse.getBody(),
StandardCharsets.UTF_8)));
throw new IllegalArgumentException("The result returned by the server is illegal");
}
UnmarshalRespUtil.unmarshalResp方法在执行时并没有做异常处理,导致CreateExternalInstanceResp resp = UnmarshalRespUtil.unmarshalResp(httpResponse, CreateExternalInstanceResp.class);执行时,直接抛出异常,不会继续向下执行,并打印出返回结果日志。
希望完善这个BUG,抛出异常可以,但应该要输出返回结果是什么,而不是JSON序列化的错误。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with UnmarshalRespUtil.unmarshalResp, called from ApprovalService$ExternalInstance.create for /open-apis/approval/v4/external_instances. Trace how the HTTP response body is handled when Gson raises JsonSyntaxException, then verify that failures preserve or log the returned response content instead of exposing only the deserialization error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100