Skip to content

Commit

Permalink
fixed reference bug in NewtonSoftConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
jrote1 committed Mar 19, 2015
1 parent 4c09ba2 commit c8c23d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions lib/src/converters/json_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ class JsonConverter implements Converter
return JSON.encode( _fromBaseObjectData( baseObjectData ) );
}

void setHashcodeInformation(Map result, String hashcode, bool hasProperties){
void setMetaData(Map result, String hashcode, ClassObjectData classObjectData){
result[_hashcodeName] = hashcode;
setTypeFromObjectType(result, classObjectData);
}

void setTypeFromObjectType(Map json, ClassObjectData classObjectData)
{
json["\$type"] = MirrorSystem.getName( reflectClass( classObjectData.objectType ).qualifiedName );
}

dynamic _fromBaseObjectData( BaseObjectData baseObjectData )
Expand All @@ -88,8 +94,7 @@ class JsonConverter implements Converter
{
var result = {
};
result["\$type"] = MirrorSystem.getName( reflectClass( baseObjectData.objectType ).qualifiedName );
setHashcodeInformation(result, baseObjectData.previousHashCode, baseObjectData.properties.length > 0);
setMetaData(result, baseObjectData.previousHashCode, baseObjectData);
baseObjectData.properties.forEach( ( name, value )
{
result[name] = _fromBaseObjectData( value );
Expand All @@ -108,13 +113,19 @@ class JsonConverter implements Converter
class NewtonSoftJsonConverter extends JsonConverter
{
@override
void setHashcodeInformation(Map result, String hashcode, bool hasProperties){
if(hasProperties)
void setMetaData(Map result, String hashcode, ClassObjectData classObjectData){
if(classObjectData.properties.length > 0 )
{
result["\$id"] = hashcode;
setTypeFromObjectType(result, classObjectData);
}

else
result["\$ref"] = hashcode;
}



@override
String getPreviousHashcode(Map json)
{
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nomirrorsmap
version: 0.0.10
version: 0.0.11
dependencies:
barback: any
dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion test/test_json/newtonsoft_test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"$type":"nomirrorsmap.tests.NewtonSoftTest","$id":"1","age":14,"gender":"m"},{"$type":"nomirrorsmap.tests.NewtonSoftTest","$ref":"1"}]
[{"$id":"1","$type":"nomirrorsmap.tests.NewtonSoftTest","age":14,"gender":"m"},{"$ref":"1"}]

0 comments on commit c8c23d6

Please sign in to comment.