3
votes

Using the FHIR .net API ( https://github.com/ewoutkramer/fhir-net-api ) I am attempting to parse a XML file and then serialise it in to JSON.

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

The first line works fine and I can see that the XML file for the bundle has been parsed and is in the "inputBundle" object.

However when I then serialise it in to JSON (the second line of code) I get an error

  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

For info the XML file I am using is taken directly from http://www.hl7.org/implement/standards/fhir/query-example-response.xml.html

Any ideas what is wrong?

1

1 Answers

1
votes

You're doing nothing wrong, this clearly looks like a bug. Would you mind reporting it here? https://github.com/ewoutkramer/fhir-net-api/issues?state=open