particle-iot / spark-server

UNMAINTAINED - An API compatible open source server for interacting with devices speaking the spark-protocol
https://www.particle.io/
GNU Affero General Public License v3.0
442 stars 136 forks source link

Date Time format for DateTime Field #82

Closed abdul2505 closed 6 years ago

abdul2505 commented 6 years ago

Hi, I am facing an issue,

I am creating an bundle object and setting the Metadata property "LastUpdated" as DateTimeOffset.Now;

When the FHIR JSON is output to response, it is showing as "resourceType": "Bundle", "id": "40127cc7-20c1-4dfc-99bc-01c06f88ebe0", "meta": { "lastUpdated": "2018-05-06T17:58:14.43+03:00" },

However, our expected format in JSON for lastUpdated/any datetime field is to be as "yyyy-MM-DDT:HH:mm:ssZ". But I get ms+UTCOff time instead of Z.

Please help us how we can achieve this lastUpdated to be of expected format while serializing the resource content to JSON.

I am using below code in customformatter class written to parse fhir+json data.

public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { return System.Threading.Tasks.Task.Factory.StartNew(() => { StreamWriter writer = new StreamWriter(writeStream); JsonWriter jsonwriter = SerializationUtil.CreateJsonTextWriter(writer); // This will use the BetterJsonWriter which handles precision correctly if (type == typeof(OperationOutcome)) { Resource resource = (Resource)value; FhirSerializer.SerializeResource(resource, jsonwriter); } else if (typeof(Resource).IsAssignableFrom(type)) { if (value != null) { Resource r = value as Resource; SummaryType st = SummaryType.False; if (r.HasAnnotation()) st = r.Annotation(); FhirSerializer.SerializeResource(r, jsonwriter, st); } } writer.Flush(); });

    }

Your help is highly appreciated.

abdul2505 commented 6 years ago

Closing this thread, as the discussion for this same issue has been available at

https://github.com/ewoutkramer/fhir-net-api/issues/598