|
When I first saw JSON, I cried. The beauty of well defined XML, the ability to verify the XML with a schema, the ability to extend the XML, the ability to have semantic meaning...all down the drain. Probably created by the same idiots people that created duck-typed languages like Ruby.
That said, I do like JSON now, certainly as a terser way of representing simple data structures. But yeah, once you get into more complex structures, the serialization / deserialization, the null handling, the complexity of instantiating a specific type derived from an abstract type...it all becomes a PITA.
So, I feel your pain.
|
|
|
|
|
Not sure why you'd be using a .NET 1-era collection instead of a Dictionary<string, string> ; but it's fairly simple to fix the issue with a custom JSON converter:
public class StringDictionaryConverter : JsonConverter
{
public override bool CanRead => true;
public override bool CanWrite => true;
public override bool CanConvert(Type objectType) => typeof(StringDictionary).IsAssignableFrom(objectType);
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var dictionary = (StringDictionary)value;
writer.WriteStartObject();
foreach (DictionaryEntry entry in dictionary)
{
writer.WritePropertyName((string)entry.Key);
writer.WriteValue(entry.Value);
}
writer.WriteEndObject();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var dictionary = existingValue as StringDictionary ?? (StringDictionary)serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
switch (reader.TokenType)
{
case JsonToken.StartObject:
{
var values = serializer.Deserialize<Dictionary<string, string>>(reader);
foreach (var pair in values)
{
dictionary.Add(pair.Key, pair.Value);
}
break;
}
case JsonToken.StartArray:
{
var values = serializer.Deserialize<List<KeyValuePair<string, string>>>(reader);
foreach (var pair in values)
{
dictionary.Add(pair.Key, pair.Value);
}
break;
}
default:
{
throw new JsonSerializationException($"Unknown token {reader.TokenType} at path {reader.Path}");
}
}
return dictionary;
}
} Example:
var source = new StringDictionary
{
["xml"] = "sucks",
["json"] = "rules",
};
string json = JsonConvert.SerializeObject(source, new StringDictionaryConverter());
var result = JsonConvert.DeserializeObject<StringDictionary>(json, new StringDictionaryConverter()); (Based on [Fork] [Fork] questions/52721999/modelstate-error-newtonsoft-json-jsonserializationexception-cannot-populate-l?noredirect=1#comment92399021_52721999 | C# Online Compiler | .NET Fiddle[^])
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is a man who wears a loincloth and lives on top of a Christmas cake called Tarzipan?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Would that make Jane a Jelly Babe?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
As long as it is not one of the Urban Dictionary definitions, then I am fine with being a British sweet.
|
|
|
|
|
No, it's not an Urban Dictionary reference, and yes, I did mean the sweet.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
It must have taken a lot of Mozart Kugeln to write that.
|
|
|
|
|
"man in a loincloth onna cake" ??? not a pretty picture (even Dibbler wouldn't go that low)
kid safe (??) examples -> https://www.cakewrecks.com/home/2013/3/13/ken-day-come-ons.html[^]
.... is the last one what you're suggesting?
after many otherwise intelligent sounding suggestions that achieved nothing the nice folks at Technet said the only solution was to low level format my hard disk then reinstall my signature. Sadly, this still didn't fix the issue!
|
|
|
|
|
Reminds me, I have Xmas Stollen to eat.
I love Marzipan, my wife hates it. Marzipan cake in Norway. Yum.
|
|
|
|
|
I really whipped Parsley out, and it turned out great. It's now devstudio integrated too.
It still could use plenty of work, but I'm also looking at exploring LL(k) and to generating the parsing code using code-synthesis instead of the cookie cutter approach most often used (and the one i currently employ in Parsley)
I *might* be able to make Parsley LL(k), but to use code-synthesis** with it would require a rewrite of much of it, and I'm not even sure it would work exactly.
So now I'm not sure if I should just start working on a separate project entirely, fork parsley, or punt this and polish parsley or what.
** generating parsing constructs using things like while loops and such instead of the current method. it looks more like handwritten code.
hack everything.
|
|
|
|
|
The best way to find direction is to lose yourself for a while.
By that, I mean do something else. I mean really else. Preferentially without a keyboard, mouse (or touch screen). Even if coding is fun. Before I did it for money, coding was my escape distraction.
Maybe even start doing something new. It can be pointless time consumption or creative. But no loops, conditionals, or other such thought should cloud the sunshine of your escape.
A fresh outlook is easier to obtain when coming in from outside.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I should probably go play in the woods but the weather is foul here right now - extremely cold, wet and windy.
hack everything.
|
|
|
|
|
|
haha i can't believe people would even willingly live like that.
hack everything.
|
|
|
|
|
Well, you could say they're, "frozen" in place.
|
|
|
|
|
|
This is actually really sound advice, I think. During one particularly rough college year, my friend and I took a trip to Myrtle Beach, in one of the Carolinas. I'm not the beach-goer type, but we set up chairs about waist high in the water, and just spent the day looking into the distance, enjoying nice local beers. That might have been one of the most relaxing, get-my-thoughts-together experiences I've had. That sort of detox or realignment might give you a clear picture of what direction you should go.
|
|
|
|
|
Interesting; I have been to Myrtle beach (South Carolina) several times, but did not step on the beach once that I remember. We did close a few bars though.
The best solutions to a problem often comes after you let the ideas peculate on in the back burner for a while. Of course if you are writing the code for someone else - that is rarely an option.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
I agree with this. Done this myself. Like a long hike down a remote and lonely trail...
#SupportHeForShe
Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
|
|
|
|
|
|
I had a home project I have been working on but I took a break to develop an idea I had for another related project - that was fun for a while then I switched back to project#1 and found I didn't like the way I had done it so started re-writing it - while doing that I had thoughts about project#2 so went back to that, found a similar project that could re-use a lot of the code and started working on project#3 (based on project#2's code base) then I couldn't decide whether to work more on project#2 or wait until I had developed more stuff for project#3 that I could retro-fit to project#2, but then... hmmm, I thought of yet another approach to project#1, similar to my first effort, which meant abandoning the code for the rewrite of project#1 and just re-doing key parts of it, hmmm...
I decided to binge watch some TV for a while and then review each project to see if it was worth working on again (at all). So then I started project#4, not related in any way to the other three. That was a lot of fun and quite a break but I got fed up with waiting on my friends to QA/play-test it - so I am currently back to binge watching (and I was very sick over the xmas vacation so did nothing but be bored and use up my precious, carefully hoarded vacation days). Now I am back at my normal job (which I like) and wondering if I should even bother with any of my home projects anymore. Bah humbug!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Uptick for relatable content
hack everything.
|
|
|
|
|
I wrote a code editor (without a backup) and my computer crashed, taking out both drives, I rewrote it in a fraction of the time, but could not recreate a (original) key algorithm that allowed it to meet my original goal (because my mind set was not the same).
(1) That lead to a cross platform regular expression template library,
(2) which lead to a cross platform Unicode template library,
(3) which lead to a cross platform meta-code template library,
(4) which lead to the original editor not being completed (to this day),
but, in the mean time, I became an expert in template programing and the C++ language in general (required for efficient cross platform template creation).
Education takes time and the best education comes from experience and lots of research - that no class can provide.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
John R. Shaw wrote: Education takes time and the best education comes from experience and lots of research
I usually get stuck on the research.
|
|
|
|
|
|