使用.net API将FHIR资源序列化为JSON

时间:2014-04-23 14:31:35

标签: hl7-fhir

使用FHIR .net API(https://github.com/ewoutkramer/fhir-net-api)我试图解析XML文件,然后将其序列化为JSON。

Bundle inputBundle = FhirParser.ParseBundleFromXml(inputStream);
Console.WriteLine(FhirSerializer.SerializeBundleToJson(inputBundle));

第一行工作正常,我可以看到该包的XML文件已被解析并位于“inputBundle”对象中。

然而,当我将其序列化为JSON(第二行代码)时,我收到错误

  System.ArgumentException: Can not add property resourceType to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
  at Newtonsoft.Json.Linq.JObject.ValidateToken(JToken o, JToken existing)
  at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
  at Newtonsoft.Json.Linq.JObject.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
  at Newtonsoft.Json.Linq.JContainer.AddInternal(Int32 index, Object content, Boolean skipParentCheck)
  at Newtonsoft.Json.Linq.JContainer.Add(Object content)
  at Hl7.Fhir.Serialization.JsonDomFhirWriter.WriteStartProperty(String name) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\JsonDomFhirWriter.cs:line 42
  at Hl7.Fhir.Serialization.ComplexTypeWriter.write(ClassMapping mapping, Object instance, PropertyMapping prop, SerializationMode mode) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ComplexTypeWriter.cs:line 75
  at Hl7.Fhir.Serialization.ComplexTypeWriter.Serialize(ClassMapping mapping, Object instance, SerializationMode mode) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ComplexTypeWriter.cs:line 48
  at Hl7.Fhir.Serialization.ResourceWriter.Serialize(Object instance, Boolean contained) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ResourceWriter.cs:line 35
  at Hl7.Fhir.Serialization.BundleJsonSerializer.getContentsAsJObject(Resource resource, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 141
  at Hl7.Fhir.Serialization.BundleJsonSerializer.createEntry(BundleEntry entry, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 94
  at Hl7.Fhir.Serialization.BundleJsonSerializer.WriteTo(Bundle bundle, JsonWriter writer, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 43
  at Hl7.Fhir.Serialization.FhirSerializer.<>c__DisplayClassd.<SerializeBundleToJson>b__c(JsonWriter jw) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 115
  at Hl7.Fhir.Serialization.FhirSerializer.jsonWriterToString(Action`1 serializer) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 198
  at Hl7.Fhir.Serialization.FhirSerializer.SerializeBundleToJson(Bundle bundle, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 115
  at fhirjx.Program.processFiles() in C:\Users\RichardKavanagh\documents\visual studio 2010\Projects\fhirjx\fhirjx\Program.cs:line 121

有关信息,我使用的XML文件直接来自http://www.hl7.org/implement/standards/fhir/query-example-response.xml.html

任何想法有什么不对?

1 个答案:

答案 0 :(得分:1)

你没有做错任何事,这显然是一个错误。你介意在这里报道吗? https://github.com/ewoutkramer/fhir-net-api/issues?state=open