目前,我正在尝试使用S4/HANA来创建TimeSheetEntries,但是我遇到了一些问题。在执行Cannot cast class java.util.HashMap to class com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.manageworkforcetimesheet.TimeSheetDataFields方法时,我收到了这样的异常:createTimeSheetEntry。我做错了什么吗?我附上了一个简单的示例,说明我是如何使用API的,如果您能指出正确的方向,我将非常感谢您的努力。
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);
}发布于 2018-02-16 12:51:46
SAP /4HANACloudSDK的最新版本已经解决了这个失败的结构化字段反序列化问题。若要更新,请在根Maven POM文件中找到<dependencyManagement>,并将sdk-bom的<version>增量为1.9.2
<?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,以确保将新的依赖项传播到所有项目模块。
发布于 2018-02-13 08:35:58
在问题得到修补之前,您可以利用OData查询生成器API和GSON进行反序列化来解决问题。
// 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"https://stackoverflow.com/questions/48729073
复制相似问题