| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Text; |
| | | 6 | | using System.Xml; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.Web; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Dispatcher |
| | | 11 | | { |
| | | 12 | | internal class JsonFormatMapping : MultiplexingFormatMapping |
| | | 13 | | { |
| | 1 | 14 | | public static readonly WebContentFormat WebContentFormat = WebContentFormat.Json; |
| | | 15 | | |
| | 1 | 16 | | private static readonly string s_defaultMediaType = JsonGlobals.ApplicationJsonMediaType; |
| | 1 | 17 | | private static readonly Dictionary<Encoding, MessageEncoder> s_encoders = new Dictionary<Encoding, MessageEncode |
| | 1 | 18 | | private static readonly object s_thisLock = new object(); |
| | | 19 | | |
| | | 20 | | public JsonFormatMapping(Encoding writeEncoding, WebContentTypeMapper contentTypeMapper) |
| | 37 | 21 | | : base(writeEncoding, contentTypeMapper) |
| | 37 | 22 | | { } |
| | | 23 | | |
| | 0 | 24 | | public override WebContentFormat ContentFormat => WebContentFormat; |
| | | 25 | | |
| | 0 | 26 | | public override WebMessageFormat MessageFormat => WebMessageFormat.Json; |
| | | 27 | | |
| | 37 | 28 | | public override string DefaultMediaType => s_defaultMediaType; |
| | | 29 | | |
| | | 30 | | protected override MessageEncoder Encoder |
| | | 31 | | { |
| | | 32 | | get |
| | | 33 | | { |
| | 0 | 34 | | lock (s_thisLock) |
| | | 35 | | { |
| | 0 | 36 | | if (!s_encoders.ContainsKey(writeEncoding)) |
| | | 37 | | { |
| | 0 | 38 | | s_encoders[writeEncoding] = new JsonMessageEncoderFactory(writeEncoding, 0, 0, new XmlDictionary |
| | | 39 | | } |
| | 0 | 40 | | } |
| | | 41 | | |
| | 0 | 42 | | return s_encoders[writeEncoding]; |
| | | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |