首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在s4sdk中创建s4sdk时出现异常

在s4sdk中创建s4sdk时出现异常
EN

Stack Overflow用户
提问于 2018-02-11 06:46:03
回答 2查看 197关注 0票数 2

目前,我正在尝试使用S4/HANA来创建TimeSheetEntries,但是我遇到了一些问题。在执行Cannot cast class java.util.HashMap to class com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.manageworkforcetimesheet.TimeSheetDataFields方法时,我收到了这样的异常:createTimeSheetEntry。我做错了什么吗?我附上了一个简单的示例,说明我是如何使用API的,如果您能指出正确的方向,我将非常感谢您的努力。

代码语言:javascript
复制
 public void createHardCodedEntry() throws ODataException {
    Calendar c = Calendar.getInstance();
    c.set(2017, Calendar.DECEMBER, Calendar.MONDAY);
    TimeSheetEntry entry = TimeSheetEntry.builder().timeSheetDate(c)
            //.timeSheetIsExecutedInTestRun(false)
            //.timeSheetIsReleasedOnSave(true)
            .timeSheetOperation("C")
            .timeSheetStatus("20")
            .personWorkAgreementExternalID("ADMINISTRATOR")
            .personWorkAgreement("50000033")
            .companyCode("1010")
            .timeSheetDataFields(TimeSheetDataFields.builder()
                    .timeSheetTaskLevel("NONE")
                    .timeSheetTaskType("ADMI")
                    .recordedHours(new BigDecimal(12))
                    .recordedQuantity(new BigDecimal(12))
                    .timeSheetTaskComponent("WORK")
                    .controllingArea("A000")
                    .hoursUnitOfMeasure("H")
                    .build())
            .build();

    ErpConfigContext erpConfigContext = new ErpConfigContext("S4HANA_CLOUD"); //this is the name of the destination configured in SCP
    TimeSheetEntry savedEntry = new DefaultManageWorkforceTimesheetService().createTimeSheetEntry(entry).execute(erpConfigContext);
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-16 12:51:46

SAP /4HANACloudSDK的最新版本已经解决了这个失败的结构化字段反序列化问题。若要更新,请在根Maven POM文件中找到<dependencyManagement>,并将sdk-bom<version>增量为1.9.2

代码语言:javascript
复制
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <!-- ... -->

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.sap.cloud.s4hana</groupId>
                <artifactId>sdk-bom</artifactId>
                <version>1.9.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!-- ... -->

</project>

在编译期间,Maven将自动从Maven中央存储库获取更新版本。只需在本地工作目录中运行mvn clean install,以确保将新的依赖项传播到所有项目模块。

票数 0
EN

Stack Overflow用户

发布于 2018-02-13 08:35:58

在问题得到修补之前,您可以利用OData查询生成器API和GSON进行反序列化来解决问题。

代码语言:javascript
复制
// use GSON for deserialization steps
final Gson gson = new Gson();

// invoke "toQuery()" to work with OData query builder API
final TimeSheetEntry savedEntry = new DefaultManageWorkforceTimesheetService()
    .createTimeSheetEntry(entry)
    .toQuery()
    .execute(new ErpConfigContext("S4HANA_CLOUD"))
    .as(TimeSheetEntry.class);

// deserialize nested TimeSheetDataFields by reading values from the "custom fields"
savedEntry.setTimeSheetDataFields(
        gson.fromJson(
            gson.toJsonTree(savedEntry.getTimeSheetDataFields().getCustomFields()),
            TimeSheetDataFields.class
        ));

// continue to work with "savedEntry"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48729073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档