config.Formatters.Remove(config.Formatters.XmlFormatter);

https://github.com/aspnet/Mvc/issues/1765

Consider only adding the JSON formatter by default #1765

https://github.com/aspnet/Mvc/issues/1765#issuecomment-69025697

  1. xml 不支持匿名类
  2. json,xml 对于只读属性的默认序列化方式不一样
  3. Here, JSON.NET by default merges lists while the xml serializer replaces it. Those are just some things I found very quickly in real world apps.(例子中的默认的list操作行为不一致,一个add,一个replace)

https://github.com/aspnet/Mvc/issues/1765#issuecomment-81937948

this used to be the case but not anymore(以前是这样,但现在不是了).

With the current bits(在当前的版本), as soon as we see */* we opt out of accept header based content negotiation and pick the first formatter available.(当我们看到 */*, 我们不在基于 accept header 做内容协商,会直接选择第一个可用的 formatter)

There is still content negotiation going on based on the runtime type of the object, so the first formatter than can handle the type wins(…..).

The jist of this design is that browsers hitting an api are not really opting into content negotiation, it is more of a way to test an API (not the right way, but a very convenient way).(这个设计的原因在于,当用浏览器访问一个web api,很大可能不是为了内容协商,更可能是测试api接口)

So we would like a consistent experience. A client on the other hand will (should) never provide a */*, as a */* is implied anyways.(所以我们有了一致的经验,其他的web client不会也不应该提供一个 */*作为 accept,因为*/*默认什么格式都行)