Skip to content

Commit

Permalink
Extract only relevant part in Json raw data when object has children …
Browse files Browse the repository at this point in the history
…objects
  • Loading branch information
gpailler committed Jun 21, 2016
1 parent c75677a commit 6ea16e2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Luxa4Slack/JsonRawConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
{
if (reader.TokenType != JsonToken.Null)
{
object instance = this.proxyGenerator.CreateClassProxy(objectType, new[] { typeof(IRawMessage) }, new RawMessageInterceptor(serializer.Context.Context as string));
string rawData = serializer.Context.Context as string;

// Extract part of the raw data if needed
if (string.IsNullOrEmpty(reader.Path) == false)
{
JObject context = JObject.Parse(rawData);
JToken token = context.SelectToken(reader.Path);
rawData = token.ToString();
}

object instance = this.proxyGenerator.CreateClassProxy(objectType, new[] { typeof(IRawMessage) }, new RawMessageInterceptor(rawData));

JObject jsonObject = JObject.Load(reader);
serializer.Populate(jsonObject.CreateReader(), instance);
Expand Down

0 comments on commit 6ea16e2

Please sign in to comment.