我正在尝试将 FHIR Resource
或 ResourceOrFeed
对象转换为 JSON 字符串。为此,我在 Java 实现中找不到任何可用的 API 方法。
有可用于 .NET api 的序列化程序,但类似的 API 不可用于 Java 实现。
关于如何将 ResourceOrFeed
对象转换为实际字符串 JSON 表示的任何指示?
Spring Jackson 转换器的默认转换对我有用,但它没有输出正确的 JSON,我不想编写自定义对象映射器。
最佳答案
尝试 HAPI fhir:http://hapifhir.io/
在pom文件中添加Maven依赖:
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>2.2-SNAPSHOT</version>
</dependency>
Java 片段:
import org.hl7.fhir.dstu3.model.*;
import ca.uhn.fhir.context.FhirContext;
// for other imports use your IDE.
public void printPatientJSON() {
FhirContext ourCtx = FhirContext.forDstu3();
Patient patient = new Patient();
patient.addName().addFamily("PATIENT");
// now convert the resource to JSON
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
System.out.println(output);
}
关于java - 使用 JAVA API 将 FHIR 资源序列化为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24049876/