Archives
-
Adoreably Awesome
These sorts of positive externalities must be supported and maintained!
Via Greg Mankin.
-
TextGlow Open Sourced
The source code for TextGlow, a Silverlight application I wrote and was launched a year ago at MIX08 to much fanfare, has been released as open source under the Microsoft Public License.
TextGlow was one of the first Silverlight 2.0 applications released and it showcased many of the new features and possibilities of Office Open XML and Silverlight.
The source code for TextGlow has been released along with an article published at OpenXML Developer, TextGlow - View Open XML Word documents with Silverlight. The article is a high level overview of the internals of TextGlow to help developers get started with their own applications.
I feel compelled to put in a disclaimer that the source code is somewhat… rough in certain places. I was the sole developer on the project and had just a couple of months to try and recreate as much as Word as possible. Fighting to keep what I had written against the constant stream of pre-MIX Silverlight 2.0 betas didn’t help either [:)]
You can find a link to the source code at the bottom of the article.
-
Json.NET Audio Interview
dev{shaped} has a CodePlex Project of the month feature where they interview the developer of an open source project.
Json.NET is their March project and I did an audio interview with Derek Hatchard, talking about what JSON is, how Json.NET makes using it in .NET easy and the trials and tribulations of managing an open source project.
Listen:
Or download the mp3 here.
If you’re trying to pick the accent, it is New Zealand. Listening to the Kiwi and American accents is very Flight of the Conchordesc.
-
Building Accessible RIAs in Microsoft Silverlight
Chris Auld, Intergen director, and Reed Shaffner, Microsoft Office technical product manager, did a presentation at MIX09 showing off ButtercupReader. The mini breakout session was called Building Accessible RIAs in Microsoft Silverlight and focuses on Silverlight’s accessibility features.
I have worked quite closely with Chris over the last few years on various projects and Reed and I presented a session at TechEd NZ last year. It is great to see them together and the video is well worth a look if you’re interested in Silverlight development.
-
Json.NET 3.5 Beta 3 – JsonSerializer improvements
An oldie but a goodie Your favourite song, and mine Ladies and gentlemen Json.NET!
JsonSerializer Improvements
This release is a rollup of the various changes since beta 2. The majority of the changes are enhancements to the way Json.NET serializes and deserializes JSON.
The most notable enhancement is the addition of IMappingResolver, previously blogged about here: Thoughts on improving JsonSerializer: IMappingResolver?
The IMappingResolver interface provides a way to globally customize how the JsonSerializer works, without any modification to your objects. I should note that the the JsonProperty attribute is still fully supported and is a great way to customize a single property. IMappingResolver is an addition and any existing Json.NET code will continue to work flawlessly.
DefaultMappingResolver
Two implementations of IMappingResolver are included in this release of Json.NET. DefaultMappingResolver is fairly self explanatory. I have tried to structure it in a way that provides many avenues of extensibility. Most of the methods on the class are protected and virtual.
CamelCaseMappingResolver
CamelCaseMappingResolver is the second implementation. This class inherits from DefaultMappingResolver and simply overrides the JSON property name to be camelcase.
Product product = new Product
{
ExpiryDate = new DateTime(2010, 12, 20, 18, 1, 0, DateTimeKind.Utc),
Name = "Widget",
Price = 9.99m,
Sizes = new[] {"Small", "Medium", "Large"}
};
string json =
JsonConvert.SerializeObject(
product,
Formatting.Indented,
new JsonSerializerSettings { MappingResolver = new CamelCaseMappingResolver() }
);
//{
// "name": "Widget",
// "expiryDate": "\/Date(1292868060000)\/",
// "price": 9.99,
// "sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
Note that camelcased property names in the serialized JSON.
CamelCaseMappingResolver is just one example of what can be achieve using IMappingResolver. Off the top of my head some other examples could be modifying the JsonSerializer to serialize private fields, or adding additional properties to a serialized JSON object like the .NET type name.
Overall I’m really happy with the way IMappingResolver has turned out. I think it provides a great halfway point between using attributes to control serializing an object, and writing a custom JsonConverter.
Simple things should be simple. Complex things should be possible. –Alan Kay
Changes
Here is a complete list of what has changed since Json.NET 3.5 Beta 2.
- New feature - Added IMappingResolver interface and DefaultMappingResolver class. IMappingResolver property added to JsonSerializer, JsonSerializerSettings, JsonSchemaGenerator
- New feature - Added CamelCaseMappingResolver
- New feature - Added DeserializeNode overload to JsonConvert that allows a root element to be added to the XML
- New feature - Added support for deserializing to IEnumerable<T>, ICollection<T>, IList<T> and IDictionary<TKey, TValue> members
- New feature – Deserializer will now populate an object’s members with unused values after creating an object from a non-default constructor
- New feature - Deserializer now attempts a case insensitive match to a member if the exact case match fails
- New feature - Added a ToString(Formatting, JsonConverters[]) overload to JToken
- New feature - Added AddAfterSelf, AddBeforeSelf methods to JToken
- Change - JsonSerializer now ignores missing members by default
- Fix - Made the error message when attempting to deserialize to an interface or abstract class clearer
- Fix - Fixed the whitespace issues when writing a raw JValue token
- Fix - XmlNodeConverter now handles nested arrays when converting JSON to XML
- Fix - Ensure JavaScriptDateTimeConverter converts nullable DateTime members
- Fix - Fix possible thread safety issues by adding double check locking to static reflection cache
Links
Json.NET 3.5 Beta 3 Download – Json.NET source code, documentation and binaries
-
Obligatory
-
ButtercupReader – A Silverlight Digital Talking Book Reader
For the second Mix in a row Intergen is launching a cool new Silverlight application: ButtercupReader!
ButtercupReader is a free Silverlight 2.0 application for viewing and playing digital talking books (DAISY) on the web by blind and partially sighted users.
As well as using Silverlight to render text and play DAISY document audio, ButtercupReader also showcases many of Silverlight’s accessibility features including screen reader support, shortcut keys, different contrast settings and zoomability. Andrew Tokeley, a member of the ButtercupReader team, has a great blog post on those features here.
I only worked briefly on this project, spiking out functionality at the beginning. It is great to see how it has all come together.
-
Sunday Podcasts
Hanselminutes - Mo Interviews Scott Hanselman
One of my highlights of TechEd NZ 2008 was meeting Scott Hanselman. Chatting about random techie things in the speakers room and working side by side to prepare our presentations was a lot of fun. Here Mo, Scott’s wife, interviews him about what it is like being The HanselMan.
Econtalk - Wales on Wikipedia
Wikipedia is a fantastic example of harnessing the cloud to collaboratively create something amazing. Jimmy Wales talks about what has made Wikipedia successful, dealing with conflict and how Wikipedia is a self managing entity.
Dungeons & Dragons Podcast – Penny Arcade Episode 1
The Penny Arcade guys are always funny and listening to them play D&D is hilarious. The first of episode of many.
-
Thoughts on improving JsonSerializer. IMappingResolver?
JsonSerializer is pretty darn flexible. It has a half dozen options on the class to customize how an object is serialized, attributes for more fine grained control and finally JsonConverters if you need to do something completely different.
The most popular request I get these days is control over how JsonSerializer determines what members on a type to serialize (e.g. serialize private as well as public properties) and control over the name of the written property (e.g. instead of “FirstName” write the property camelcase style: “firstName”).
Controlling this behaviour is actually already possible by inheriting from JsonSerializer and overriding GetMemberMappings. The MemberMapping class contains all the information about how a .NET member gets mapped to a JSON property (name, readable, writable, converter, etc) and is used internally by JsonSerializer. The problem is it isn’t terribly discoverable to the average user.
IMappingResolver
What I am thinking of doing is adding is an IMappingResolver interface.
public interface IMappingResolver
{
JsonMemberMappingCollection ResolveMappings(Type type);
}
JsonSerializer would have a MappingResolver property and the instance of the object assigned to it would determine how the members on a .NET class get mapped to a JSON object (if you’re hip with the GOF urban street lingo this is an example of the strategy pattern).
Examples of resolvers that could come with Json.NET or you could create yourself: CamelCaseMappingResolver, TypeDescriptorMappingResolver, PrivateMembersMappingResolver and so on.
I like this over inheritance because it is obvious and in a user’s face. MappingResolver could also be added to the JsonSerializerSettings class and used from the serialization helper methods on JsonConvert.
Yay or nay? Suggestions welcome [:)]