Changing the default serialization format of the GUID

By default, JSON and XML serializers in Web API 2 simply call ToString() to serialize the Guid instruction, which means it includes a dash: fd190000-5532-8477-e053-9a16ce0af828 . I would really like to change the default serialization to the format returned by ToString("N") , which does not include a dash: fd19000055328477e0539a16ce0af828 .

I found this article about creating a JsonConverter and overriding the WriteJson() method to use ToString("N") . This works fine for JSON, but I did not find anything like serializing XML.

Is there a way to implement this only once, no matter how many MediaTypeFormatters are present? If not, how can I override XML serialization?

+5
source share

Source: https://habr.com/ru/post/1200341/


All Articles