Skip to content

Commit

Permalink
Revert "Deserializes nested complex types properly."
Browse files Browse the repository at this point in the history
This reverts commit 33a78fd.

See issue #311
  • Loading branch information
simendsjo authored and cskardon committed Nov 20, 2018
1 parent 3b45cff commit 7918f21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
10 changes: 3 additions & 7 deletions Neo4jClient.Shared/StatementResultHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static string ToJsonString(this IRelationship relationship, bool inSet
return $"{{\"data\":{{ {string.Join(",", props)} }}}}";
}

internal static string ToJsonString(this object o, bool inSet, bool isNested, bool isNestedInList, bool isConcreteType = false)
internal static string ToJsonString(this object o, bool inSet, bool isNested, bool isNestedInList)
{
if (o == null)
return null;
Expand Down Expand Up @@ -119,8 +119,6 @@ internal static string ToJsonString(this object o, bool inSet, bool isNested, bo
output.Add(s);
}

if (isConcreteType)
return string.Join(",", output);
return $"{{ {string.Join(",", output)} }}";
}

Expand All @@ -146,8 +144,7 @@ internal static string ToJsonString(this object o, bool inSet, bool isNested, bo
}
else if (eType == typeof(Dictionary<string, object>))
{
//here!!
output.Add($"{{{e.ToJsonString(inSet, false, true, isConcreteType) ?? "null"}}}");
output.Add($"{{{e.ToJsonString(inSet, false, true) ?? "null"}}}");
onlyKvp = false;
}
else
Expand Down Expand Up @@ -192,8 +189,7 @@ public static IEnumerable<T> Deserialize<T>(this IRecord record, ICypherJsonDese
continue;
}

var isConcreteComplexType = !typeT.IsPrimitive() && !typeT.IsAnonymous();
data.Add(o.ToJsonString(convertMode == CypherResultMode.Set, record.Keys.Count > 1, false, isConcreteComplexType));
data.Add(o.ToJsonString(convertMode == CypherResultMode.Set, record.Keys.Count > 1, false));
}

var format = "{{ {0}, \"data\":[[ {1} ]] }}";
Expand Down
29 changes: 0 additions & 29 deletions Neo4jClient.Tests.Shared/StatementResultHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,6 @@ public RecordWithList()
}
}

public class ComplexRecord
{
public int Id { get; set; }
}

public class RecordWithListOfComplex
{
public IEnumerable<ComplexRecord> Data { get; set;}
}

[Fact]
public void DeserializeRecordWithListCorrectly()
{
Expand All @@ -200,25 +190,6 @@ public void DeserializeRecordWithListCorrectly()
mockDeserializer.Verify(d => d.Deserialize(expectedContent), Times.Once);
}

[Fact]
public void DeserializeComplexTypeInList()
{
var list = new List<object> {new Dictionary<string, object> {{"Id", 1}}};

var record = Substitute.For<IRecord>();
record.Keys.Returns(new List<string> {"Data"});
record["Data"].Returns(list);

var expectedContent = "{ \"columns\":[\"Data\"], \"data\":[[ [{\"Id\":1}] ]] }";
var mockDeserializer = new Mock<ICypherJsonDeserializer<RecordWithListOfComplex>>();
mockDeserializer
.Setup(d => d.Deserialize(It.IsAny<string>()))
.Returns(new List<RecordWithListOfComplex>());

record.Deserialize(mockDeserializer.Object, CypherResultMode.Projection);
mockDeserializer.Verify(d => d.Deserialize(expectedContent), Times.Once);
}

[Fact]
public void DeserializeSetCorrectly()
{
Expand Down

0 comments on commit 7918f21

Please sign in to comment.