Skip to content

Commit e35c992

Browse files
Merge pull request #164 from nefarius/nefarius/issues/163
Fixes Bad Request on Attachment Upload
2 parents 09cb34a + 8f9c81f commit e35c992

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using CouchDB.Driver.Types;
5+
using Newtonsoft.Json;
6+
7+
namespace CouchDB.Driver.Converters
8+
{
9+
internal class AttachmentsParsedConverter : JsonConverter<Dictionary<string, CouchAttachment>>
10+
{
11+
public override void WriteJson(JsonWriter writer, Dictionary<string, CouchAttachment> value,
12+
JsonSerializer serializer)
13+
{
14+
serializer.Serialize(writer, value
15+
.Where(kvp => kvp.Value.FileInfo is null)
16+
.ToDictionary(k => k.Key, v => v.Value)
17+
);
18+
}
19+
20+
public override bool CanRead => false;
21+
22+
public override Dictionary<string, CouchAttachment> ReadJson(JsonReader reader, Type objectType,
23+
Dictionary<string, CouchAttachment> existingValue, bool hasExistingValue,
24+
JsonSerializer serializer)
25+
{
26+
throw new NotImplementedException();
27+
}
28+
}
29+
}

src/CouchDB.Driver/Types/CouchDocument.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable disable
22
using System.Collections.Generic;
33
using System.Runtime.Serialization;
4+
using CouchDB.Driver.Converters;
45
using Newtonsoft.Json;
56

67
namespace CouchDB.Driver.Types
@@ -47,6 +48,7 @@ protected CouchDocument()
4748
// This must be for serialization only field
4849
[DataMember]
4950
[JsonProperty("_attachments", NullValueHandling = NullValueHandling.Ignore)]
51+
[JsonConverter(typeof(AttachmentsParsedConverter))]
5052
private Dictionary<string, CouchAttachment> AttachmentsParsed { get; set; }
5153

5254
[JsonIgnore]

0 commit comments

Comments
 (0)