Skip to content

Commit

Permalink
ImageService3 deserialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldgray committed May 12, 2022
1 parent af11605 commit 3051776
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ public void CanDeserialiseSerialisedManifest()
Context = ImageService2.Image2Context,
Width = 1000,
Height = 1001
},
new ImageService3
{
Id = "https://test.example.com/canvas/1/image/3",
Profile = ImageService3.Level2Profile,
Context = ImageService3.Image3Context,
Width = 1000,
Height = 1001
}
},
}
Expand Down
3 changes: 3 additions & 0 deletions src/IIIF/IIIF/ImageApi/Service/ImageService3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace IIIF.ImageApi.Service
public class ImageService3 : ResourceBase
{
public const string Image3Context = "http://iiif.io/api/image/3/context.json";
public const string Level0Profile = "level0";
public const string Level1Profile = "level1";
public const string Level2Profile = "level2";
public const string ImageProtocol = "http://iiif.io/api/image";

public override string Type => nameof(ImageService3);
Expand Down
27 changes: 22 additions & 5 deletions src/IIIF/IIIF/Serialisation/Deserialisation/ServiceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,29 @@ public class ServiceConverter : ReadOnlyConverter<IService>

if (service == null)
{
service = jsonObject["@type"].Value<string>() switch
var atType = jsonObject["@type"];
if (atType != null)
{
"SearchService1" => new Search.V1.SearchService(),
nameof(ImageApi.Service.ImageService2) => new ImageApi.Service.ImageService2(),
_ => null
};
service = atType.Value<string>() switch
{
"SearchService1" => new Search.V1.SearchService(),
nameof(ImageApi.Service.ImageService2) => new ImageApi.Service.ImageService2(),
_ => null
};
}
}

if (service == null)
{
var type = jsonObject["type"];
if (type != null)
{
service = type.Value<string>() switch
{
nameof(ImageApi.Service.ImageService3) => new ImageApi.Service.ImageService3(),
_ => null
};
}
}

// TODO handle ResourceBase items?
Expand Down

0 comments on commit 3051776

Please sign in to comment.