Skip to content

Commit 34596a4

Browse files
committed
Merge pull request #111 from WebApiContrib/dev
Dev
2 parents 44d2aff + 1678207 commit 34596a4

27 files changed

+80
-212
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CollectionJson.NET
22

3+
[![collectionjson MyGet Build Status](https://www.myget.org/BuildSource/Badge/collectionjson?identifier=0f0fe557-4dbb-441d-bc44-6bf81c736ceb)](https://www.myget.org/)
4+
35
This library provides support for using the [Collection+JSON] (http://amundsen.com/media-types/collection/) hypermedia mediatype authored by [Mike Amundsen] (http://twitter.com/mamund).
46

57
## Features

samples/friendapi/FriendApi.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<HintPath>packages\Autofac.WebApi2.3.3.3\lib\net45\Autofac.Integration.WebApi.dll</HintPath>
4646
<Private>True</Private>
4747
</Reference>
48+
<Reference Include="DynamicUtils">
49+
<HintPath>packages\DynamicUtils.1.0.1\lib\portable-net45+sl50+win+wp80\DynamicUtils.dll</HintPath>
50+
</Reference>
4851
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4952
<HintPath>packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
5053
</Reference>

samples/friendapi/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<packages>
33
<package id="Autofac" version="3.5.0" targetFramework="net45" />
44
<package id="Autofac.WebApi2" version="3.3.3" targetFramework="net45" />
5+
<package id="DynamicUtils" version="1.0.1" targetFramework="net45" />
56
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" />
67
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" />
78
<package id="Microsoft.AspNet.WebApi.SelfHost" version="5.2.0" targetFramework="net45" />

src/CollectionJson.Client/CollectionJson.Client.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<Prefer32Bit>false</Prefer32Bit>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<Reference Include="DynamicUtils">
41+
<HintPath>..\packages\DynamicUtils.1.0.1\lib\portable-net40+sl50+win8+wpa81+wp8+monotouch+monoandroid\DynamicUtils.dll</HintPath>
42+
</Reference>
4043
<Reference Include="Newtonsoft.Json">
4144
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
4245
</Reference>

src/CollectionJson.Client/CollectionJson.Client.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
</dependencies>
2020
</metadata>
2121
<files>
22-
<file src="bin\Release\CollectionJson.Client.dll" target="lib\portable-net45+win8+wp8+monotouch+monoandroid" />
22+
<file src="bin\Release\CollectionJson.Client.dll" target="lib\portable-net40+sl50+win8+wpa81+wp8+monotouch+monoandroid" />
2323
</files>
2424
</package>

src/CollectionJson.Client/CollectionJsonContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CollectionJsonContent(Collection collection)
3030
_readDocument = new ReadDocument();
3131
_readDocument.Collection = collection;
3232

33-
Headers.ContentType = new MediaTypeHeaderValue("application/vnd.collection+json");
33+
Headers.ContentType = new MediaTypeHeaderValue(Collection.MediaType);
3434
}
3535

3636

src/CollectionJson.Client/CollectionJsonFormatter.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
using System.Reflection;
1+
using System.Net.Http;
2+
using System.Net.Http.Headers;
3+
using System.Reflection;
24
using System.Runtime.InteropServices.WindowsRuntime;
5+
using System.Threading.Tasks;
36
using Newtonsoft.Json;
47
using Newtonsoft.Json.Linq;
58
using Newtonsoft.Json.Serialization;
@@ -15,9 +18,9 @@ namespace CollectionJson.Client
1518
{
1619
public class CollectionJsonFormatter : JsonMediaTypeFormatter
1720
{
18-
public CollectionJsonFormatter()
21+
public CollectionJsonFormatter()
1922
{
20-
SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("application/vnd.collection+json"));
23+
SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue(Collection.MediaType));
2124
SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
2225
SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
2326
SerializerSettings.ContractResolver =
@@ -53,6 +56,17 @@ public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object
5356
return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
5457
}
5558

59+
60+
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
61+
{
62+
if (typeof (IWriteDocument).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) &
63+
type != typeof (WriteDocument))
64+
{
65+
return base.ReadFromStreamAsync(typeof (WriteDocument), readStream, content, formatterLogger);
66+
}
67+
return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
68+
}
69+
5670
private class ReadDocumentDecorator : IReadDocument
5771
{
5872
private readonly IReadDocument _innerReadDocument;

src/CollectionJson.Client/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="DynamicUtils" version="1.0.1" targetFramework="portable-net45+win+wpa81+wp80" />
34
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10" />
45
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10" />
56
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="portable-net45+win+wpa81+wp80+MonoAndroid10+MonoTouch10" />

src/CollectionJson/Collection.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
using System.Runtime.Serialization;
55
using System.Text;
66
using System.Xml;
7+
using DynamicUtils;
78

89
namespace CollectionJson
910
{
1011
[DataContract]
1112
public class Collection : ExtensibleObject
1213
{
14+
public const string MediaType = "application/vnd.collection+json";
15+
1316
public Collection()
1417
{
1518
Links = new List<Link>();

src/CollectionJson/CollectionJson.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<Prefer32Bit>false</Prefer32Bit>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<Reference Include="DynamicUtils">
41+
<HintPath>..\packages\DynamicUtils.1.0.1\lib\portable-net40+sl50+win8+wpa81+wp8+monotouch+monoandroid\DynamicUtils.dll</HintPath>
42+
</Reference>
4043
<Reference Include="System" />
4144
<Reference Include="System.Core" />
4245
<Reference Include="System.Xml" />
@@ -50,7 +53,6 @@
5053
<Compile Include="CollectionJsonDocumentWriterExtensions.cs" />
5154
<Compile Include="Data.cs" />
5255
<Compile Include="Error.cs" />
53-
<Compile Include="ExtensibleObject.cs" />
5456
<Compile Include="ICollectionJsonDocumentReader_Of_T.cs" />
5557
<Compile Include="ICollectionJsonDocumentWriter_Of_T.cs" />
5658
<Compile Include="IEnumerable_Of_DataExtensions.cs" />
@@ -69,6 +71,7 @@
6971
<None Include="CollectionJson.nuspec">
7072
<SubType>Designer</SubType>
7173
</None>
74+
<None Include="packages.config" />
7275
</ItemGroup>
7376
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
7477
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)