You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using (TextReader reader = new StreamReader(stem))
return NetJSON.NetJSON.Deserialize<T>(reader);
into the following object
public class Tracker {
[NetJSONProperty("Tracker_Name")]
public string Name { get; set; }
[NetJSONProperty("Tracker_SearchTerm")]
public string SearchTerm { get; set; }
[NetJSONProperty("Tracker_SortBy")]
public string SortBy { get; set; }
}
I get not null object where all properties are set to null. The strange thing is that it somehow reacts to value "xxxx x". If I have there instead "xxxxx" or "xxx xx" it works just fine. For some reason only certain combinations yield error. If JSON string has "Tracker_Name" as last param then first 2 params get correct value and name still be null.
If JSON string has space before " :" then deserializing works fine for any value.
The same manipulation with "Tracker_SearchTerm" param appear to have no affect on result. For some reason only Name property does that...
Not sure why this happens. Perhaps I need to setup something extra but I am not sure what...
I tried to reproduce it in multiple ways and I can't. I tried using a text file (load using stream), used a json string with both values that you said is invalid and it always works. What version are you using?
Looking at you sample data it is hard to say if you have a spaces around ":". After posting this I was looking for temp workaround for us as I want to keep using your library. Here is what I did for work around:
public static T fromStream<T>(Stream strm) {
using (TextReader reader = new StreamReader(strm)) {
string text = reader.ReadToEnd().Replace("\":", "\" :");
T t = NetJSON.NetJSON.Deserialize<T>(text);
return t;
}
}
Not sure when I can make a sample project. Perhaps this might help.
The following does not get deserialized correctly:
public static T fromStream<T>(Stream strm) {
using (TextReader reader = new StreamReader(strm)) {
string text = "{\n\"Tracker_SortBy\":\"Relevance\",\n\"Tracker_Name\":\"Wind Power Org\",\n\"Profile_Tracker_ID\":1428,\n\"Tracker_ContentType\":\"1\",\n\"Tracker_SearchTerm\":\"Wind Power\",\n\"Tracker_Facets\":[\n{\"Tracker_Facet\":\"{fb8d09e1-5024-419e-9703-598945af8139}\"},\n{\"Tracker_Facet\":\"{90ec93d4-e1bd-4215-acf0-eac1e2fd5f6d}\"}]\n}";
Tracker t = NetJSON.NetJSON.Deserialize<Tracker>(text);
return default(T);
}
}
Tracker Class:
public class Tracker {
[NetJSONProperty("Tracker_Name")]
public string Name { get; set; }
[NetJSONProperty("Profile_Tracker_ID")]
public int ID { get; set; }
[NetJSONProperty("Tracker_ContentType")]
public string ContentType { get; set; }
[NetJSONProperty("Tracker_SearchTerm")]
public string SearchTerm { get; set; }
[NetJSONProperty("Tracker_SortBy")]
public string SortBy { get; set; }
[NetJSONProperty("Tracker_Facets")]
public System.Collections.Generic.List<Facet> FacetCollection { get; set; }
}
}
Facets class
public class Facet {
public Facet() { }
public Facet(string _facet) {
//Value = _facet;
}
[NetJSONProperty("Profile_Tracker_Facets_ID")]
public int ID { get; set; }
[NetJSONProperty("Profile_Tracker_ID")]
public int TrackerID { get; set; }
[NetJSONProperty("Tracker_Facet")]
public Guid Value { get; set; }
}
public class Tracker
{
[NetJSONProperty("Tracker_Name")]
public string Name { get; set; }
[NetJSONProperty("Profile_Tracker_ID")]
public int ID { get; set; }
[NetJSONProperty("Tracker_ContentType")]
public string ContentType { get; set; }
[NetJSONProperty("Tracker_SearchTerm")]
public string SearchTerm { get; set; }
[NetJSONProperty("Tracker_SortBy")]
public string SortBy { get; set; }
}
The issue with it also reading the result and getting null for some is due to the effect of UseStringOptimization which tries to avoid doing character by character reading of json string to improve performance.
Activity
rpgmaker commentedon Dec 9, 2016
Thanks for the find. I will take a look at it over the weekend and try to come up with a resolution.
Thanks,
rpgmaker commentedon Dec 11, 2016
I tried to reproduce it in multiple ways and I can't. I tried using a text file (load using stream), used a json string with both values that you said is invalid and it always works. What version are you using?
protyagov commentedon Dec 13, 2016
Looking at you sample data it is hard to say if you have a spaces around ":". After posting this I was looking for temp workaround for us as I want to keep using your library. Here is what I did for work around:
I am using version 1.2.1.5 from NuGen
rpgmaker commentedon Dec 13, 2016
Funny I am not getting same issue with same code.
rpgmaker commentedon Dec 13, 2016
It might be an encoding issue. Could you recreate the issue in a sample project and upload it here?
Thanks,
protyagov commentedon Dec 13, 2016
Yes, strange thing.
Will try to provide you with something as soon as I can.
rpgmaker commentedon Dec 13, 2016
In my sample data I am using same values you provided I am not including any spaces.
protyagov commentedon Dec 13, 2016
Just posted a quick video with real example on what I am doing:
https://youtu.be/F8AV86CWRyw
Not sure when I can make a sample project. Perhaps this might help.
The following does not get deserialized correctly:
Tracker Class:
Facets class
NimaAra commentedon Dec 13, 2016
It seems the issue is related to the
IDproperty.Given a model:
The following returns
nullfor all properties:Now if you delete the
IDproperty everything is deserialized correctly.On another interesting issue, if you change the input to:
Note it is the same input I have just inserted a tab at the beginning of each line, now the program goes into a never ending loop :-(
@rpgmaker, I remember I opened an issue related to this and as far as I remember you did actually fix it but here it is manifesting again.
rpgmaker commentedon Dec 13, 2016
The issue with it looping forever is the UseStringOptimization option, setting it to false fixes the problem. I will see what I can do to fix it.
Thanks,
rpgmaker commentedon Dec 14, 2016
The issue has been resolved and pushed to nuget also
https://www.nuget.org/packages/NetJSON/
I hope it did not broke anything because all my unit test pass including the new two unit test i wrote
rpgmaker commentedon Dec 14, 2016
The issue with it also reading the result and getting null for some is due to the effect of UseStringOptimization which tries to avoid doing character by character reading of json string to improve performance.
protyagov commentedon Dec 14, 2016
Thank you for quick fix. Switched project to 1.6 and everything now appear to work correctly.