无法解析导入 org.apache.olingo.commons.api.format.ODataFormat

The import org.apache.olingo.commons.api.format.ODataFormat cannot be resolved

我已经尝试 运行 java 在 Apache Olingo 中使用 OData 服务进行项目 API。

但是我收到 "import org.apache.olingo.commons.api.format.ODataFormat cannot be resolved" 错误。

我知道为相应的 Java 文件导入 API 路径来解决这个问题。但我找不到合适的。任何人都可以帮助解决这个问题。

示例文件路径:https://apache.googlesource.com/olingo-odata4/+/Tutorial_P4_Navigation/samples/tutorials/p1_read?autodive=0%2F%2F

您链接的教程基于 4.0.0-beta-03 版本的 Olingo。 ODataFormat 不再需要了。

相反

ODataFormat format = ODataFormat.fromContentType(responseFormat);
ODataSerializer serializer = odata.createSerializer(format);

你可以选择

ODataSerializer serializer = odata.createSerializer(responseFormat);

responseFormat 在这两种情况下都是 ContentType 类型。

官方教程中的代码是最新的:https://olingo.apache.org/doc/odata4/index.html