Hi,
I was using Autowrapper. Some contents breaking my json schema.
I am getting this issue.
An error occured deserializing the response.
I used [AutoWrapIgnore] everything goes well. But AutoWrapper not worked for me.
var jsonString = JsonSerializer.Serialize(models); //using with system.text.json (valid json)
{
"Items": [
{
"Id": "eec80803-1927-4c48-9595-edd877acba44",
"CreatedAt": "2021-02-25T12:06:29+00:00",
"Title": "What is an SEO friendly url, how to create it?",
"ShortDescription": "It is the general concern of all of us, to be visible in the internet ocean. Also, no matter how good you do, it will make no sense if you are unable to promote and market your product. In order to take you one step forward in this way, we will talk about what is the SEO friendly url that will increase your score on Google and how to do it.",
"Content": "SEO (Search Engine Optimization) consists of the abbreviation of the words. 90% of most of the traffic to your site comes from search engines such as Google, Bing, Yandex, Yahoo, Yaani etc. In order for people to reach you better, we must comply with the standards set by these engines. Otherwise, we will fall down in the google rankings and you will find yourself in the internet garbage.\r\n\r\nSEO is a very comprehensive issue and I will only tell you how to create SEO Friendly Url.\r\n\r\nFirst, let\u0027s create a Utils class. No need to explain what the code buffer does in general :) I\u0027ll explain how to use it at the bottom.\r\n```csharp\r\nusing System.Globalization;\r\nusing System.Text;\r\n\r\nnamespace Project.Core.Helpers\r\n{\r\n public static class Utils\r\n {\r\n /// \u003csummary\u003e\r\n /// Creates a URL And SEO friendly slug\r\n /// \u003c/summary\u003e\r\n /// \u003cparam name\u003d\"text\"\u003eText to slugify\u003c/param\u003e\r\n /// \u003cparam name\u003d\"maxLength\"\u003eMax length of slug\u003c/param\u003e\r\n /// \u003creturns\u003eURL and SEO friendly string\u003c/returns\u003e\r\n public static string PrepareSeoUrl(string text, int maxLength \u003d 0)\r\n {\r\n // Return empty value if text is null\r\n if (text \u003d\u003d null) return \"\";\r\n text \u003d text.Replace(\"İ\", \"i\");\r\n\r\n var normalizedString \u003d text\r\n // Make lowercase\r\n .ToLowerInvariant()\r\n // Normalize the text\r\n .Normalize(NormalizationForm.FormD);\r\n\r\n var stringBuilder \u003d new StringBuilder();\r\n var stringLength \u003d normalizedString.Length;\r\n var prevdash \u003d false;\r\n var trueLength \u003d 0;\r\n\r\n for (var i \u003d 0; i \u003c stringLength; i++)\r\n {\r\n var c \u003d normalizedString[i];\r\n\r\n switch (CharUnicodeInfo.GetUnicodeCategory(c))\r\n {\r\n // Check if the character is a letter or a digit if the character is a\r\n // international character remap it to an ascii valid character\r\n case UnicodeCategory.LowercaseLetter:\r\n case UnicodeCategory.UppercaseLetter:\r\n case UnicodeCategory.DecimalDigitNumber:\r\n if (c \u003c 128)\r\n stringBuilder.Append(c);\r\n else\r\n stringBuilder.Append(RemapInternationalCharToAscii(c));\r\n\r\n prevdash \u003d false;\r\n trueLength \u003d stringBuilder.Length;\r\n break;\r\n\r\n // Check if the character is to be replaced by a hyphen but only if the last character wasn\u0027t\r\n case UnicodeCategory.SpaceSeparator:\r\n case UnicodeCategory.ConnectorPunctuation:\r\n case UnicodeCategory.DashPunctuation:\r\n case UnicodeCategory.OtherPunctuation:\r\n case UnicodeCategory.MathSymbol:\r\n if (!prevdash)\r\n {\r\n stringBuilder.Append(\u0027-\u0027);\r\n prevdash \u003d true;\r\n trueLength \u003d stringBuilder.Length;\r\n }\r\n\r\n break;\r\n }\r\n\r\n // If we are at max length, stop parsing\r\n if (maxLength \u003e 0 \u0026\u0026 trueLength \u003e\u003d maxLength)\r\n break;\r\n }\r\n\r\n // Trim excess hyphens\r\n var result \u003d stringBuilder.ToString().Trim(\u0027-\u0027);\r\n\r\n // Remove any excess character to meet maxlength criteria\r\n return maxLength \u003c\u003d 0 || result.Length \u003c\u003d maxLength ? result : result.Substring(0, maxLength);\r\n }\r\n\r\n /// \u003csummary\u003e\r\n /// Remaps international characters to ascii compatible ones\r\n /// based of: https://meta.stackexchange.com/questions/7435/non-us-ascii-characters-dropped-from-full-profile-url/7696#7696\r\n /// \u003c/summary\u003e\r\n /// \u003cparam name\u003d\"c\"\u003eCharcter to remap\u003c/param\u003e\r\n /// \u003creturns\u003eRemapped character\u003c/returns\u003e\r\n private static string RemapInternationalCharToAscii(char c)\r\n {\r\n var s \u003d c.ToString().ToLowerInvariant();\r\n if (\"àåáâäãåą\".Contains(s))\r\n return \"a\";\r\n if (\"èéêëę\".Contains(s))\r\n return \"e\";\r\n if (\"ìíîïı\".Contains(s))\r\n return \"i\";\r\n if (\"òóôõöøőð\".Contains(s))\r\n return \"o\";\r\n if (\"ùúûüŭů\".Contains(s))\r\n return \"u\";\r\n if (\"çćčĉ\".Contains(s))\r\n return \"c\";\r\n if (\"żźž\".Contains(s))\r\n return \"z\";\r\n if (\"śşšŝ\".Contains(s))\r\n return \"s\";\r\n if (\"ñń\".Contains(s))\r\n return \"n\";\r\n if (\"ýÿ\".Contains(s))\r\n return \"y\";\r\n if (\"ğĝ\".Contains(s))\r\n return \"g\";\r\n return c switch\r\n {\r\n \u0027ř\u0027 \u003d\u003e \"r\",\r\n \u0027ł\u0027 \u003d\u003e \"l\",\r\n \u0027đ\u0027 \u003d\u003e \"d\",\r\n \u0027ß\u0027 \u003d\u003e \"ss\",\r\n \u0027þ\u0027 \u003d\u003e \"th\",\r\n \u0027ĥ\u0027 \u003d\u003e \"h\",\r\n \u0027ĵ\u0027 \u003d\u003e \"j\",\r\n _ \u003d\u003e \"\"\r\n };\r\n }\r\n }\r\n}\r\n```\r\n\r\n\r\n```csharp\r\nvar blogPost \u003d new BlogPost();\r\nblogPost.Url \u003d Utils.PrepareSeoUrl(\"New Title\", 50);\r\n// blogPost.Url output \u003d\u003e new-title\r\n```\r\n\r\nAs you can see in the example above, you can convert a text to an SEO Friendly Url. If you add the url with this helper method while writing a url on your listing pages, people will use this url and search engine bots will recognize this url over time and add it to their list.\r\n\r\nI\u0027m adding code to guide you on how to capture this url in case you need it.\r\n\r\n```csharp\r\n[Route(\"blog/{slug}\")]\r\npublic async Task\u003cIActionResult\u003e Details(string slug)\r\n{\r\n try\r\n {\r\n var model \u003d await db.Table.FirstOrDefaultAsync(_ \u003d\u003e _.Url \u003d\u003d slug)\r\n return View(model);\r\n }\r\n catch (Exception ex)\r\n {\r\n\t\t\t\t// TODO add not found page\r\n return RedirectToAction(\"Index\");\r\n }\r\n}\r\n```",
"TitleImageFile": {
"Id": "92463ebf-171e-45e8-9169-b8d562efb967",
"CreatedAt": "2021-02-25T12:08:10+00:00",
"Extension": ".png",
"ContentType": "image/png",
"Size": 538230,
"FileUrl": "***",
"ThumbnailFileUrl": "***"
}
}
],
"Pagination": {
"TotalItemCount": 1
}
}
this response with autowrapper. json schema breaked
{
"statusCode": 200,
"message": "GET Request successful.",
"result": {
"items": [
{
"id": "eec80803-1927-4c48-9595-edd877acba44",
"createdAt": "2021-02-25T12:06:29+00:00",
"title": "What is an SEO friendly url, how to create it?",
"shortDescription": "It is the general concern of all of us, to be visible in the internet ocean. Also, no matter how good you do, it will make no sense if you are unable to promote and market your product. In order to take you one step forward in this way, we will talk about what is the SEO friendly url that will increase your score on Google and how to do it.",
"content": "SEO (Search Engine Optimization) consists of the abbreviation of the words. 90% of most of the traffic to your site comes from search engines such as Google, Bing, Yandex, Yahoo, Yaani etc. In order for people to reach you better, we must comply with the standards set by these engines. Otherwise, we will fall down in the google rankings and you will find yourself in the internet garbage. SEO is a very comprehensive issue and I will only tell you how to create SEO Friendly Url. First, let's create a Utils class. No need to explain what the code buffer does in general :) I'll explain how to use it at the bottom. ```csharp using System.Globalization; using System.Text; namespace Project.Core.Helpers { public static class Utils { /// /// Creates a URL And SEO friendly slug /// /// Text to slugify /// Max length of slug /// URL and SEO friendly string public static string PrepareSeoUrl(string text, int maxLength = 0) { // Return empty value if text is null if (text == null) return ""; text = text.Replace("İ", "i"); var normalizedString = text // Make lowercase .ToLowerInvariant() // Normalize the text .Normalize(NormalizationForm.FormD); var stringBuilder = new StringBuilder(); var stringLength = normalizedString.Length; var prevdash = false; var trueLength = 0; for (var i = 0; i stringLength; i++) { var c = normalizedString[i]; switch (CharUnicodeInfo.GetUnicodeCategory(c)) { // Check if the character is a letter or a digit if the character is a // international character remap it to an ascii valid character case UnicodeCategory.LowercaseLetter: case UnicodeCategory.UppercaseLetter: case UnicodeCategory.DecimalDigitNumber: if (c 128) stringBuilder.Append(c); else stringBuilder.Append(RemapInternationalCharToAscii(c)); prevdash = false; trueLength = stringBuilder.Length; break; // Check if the character is to be replaced by a hyphen but only if the last character wasn't case UnicodeCategory.SpaceSeparator: case UnicodeCategory.ConnectorPunctuation: case UnicodeCategory.DashPunctuation: case UnicodeCategory.OtherPunctuation: case UnicodeCategory.MathSymbol: if (!prevdash) { stringBuilder.Append('-'); prevdash = true; trueLength = stringBuilder.Length; } break; } // If we are at max length, stop parsing if (maxLength > 0 && trueLength >= maxLength) break; } // Trim excess hyphens var result = stringBuilder.ToString().Trim('-'); // Remove any excess character to meet maxlength criteria return maxLength = 0 || result.Length = maxLength ? result : result.Substring(0, maxLength); } /// /// Remaps international characters to ascii compatible ones /// based of: https://meta.stackexchange.com/questions/7435/non-us-ascii-characters-dropped-from-full-profile-url/7696#7696 /// /// Charcter to remap /// Remapped character private static string RemapInternationalCharToAscii(char c) { var s = c.ToString().ToLowerInvariant(); if ("àåáâäãåą".Contains(s)) return "a"; if ("èéêëę".Contains(s)) return "e"; if ("ìíîïı".Contains(s)) return "i"; if ("òóôõöøőð".Contains(s)) return "o"; if ("ùúûüŭů".Contains(s)) return "u"; if ("çćčĉ".Contains(s)) return "c"; if ("żźž".Contains(s)) return "z"; if ("śşšŝ".Contains(s)) return "s"; if ("ñń".Contains(s)) return "n"; if ("ýÿ".Contains(s)) return "y"; if ("ğĝ".Contains(s)) return "g"; return c switch { 'ř' => "r", 'ł' => "l", 'đ' => "d", 'ß' => "ss", 'þ' => "th", 'ĥ' => "h", 'ĵ' => "j", _ => "" }; } } } ``` ```csharp var blogPost = new BlogPost(); blogPost.Url = Utils.PrepareSeoUrl("New Title", 50); // blogPost.Url output => new-title ``` As you can see in the example above, you can convert a text to an SEO Friendly Url. If you add the url with this helper method while writing a url on your listing pages, people will use this url and search engine bots will recognize this url over time and add it to their list. I'm adding code to guide you on how to capture this url in case you need it. ```csharp [Route("blog/{slug
}")] public async Task Details(string slug) { try { var model = await db.Table.FirstOrDefaultAsync(_ => _.Url == slug) return View(model); } catch (Exception ex) { // TODO add not found page return RedirectToAction("Index"); } } ```",
"titleImageFile": {
"id": "92463ebf-171e-45e8-9169-b8d562efb967",
"createdAt": "2021-02-25T12:08:10+00:00",
"extension": ".png",
"contentType": "image/png",
"size": 538230,
"fileUrl": "***",
"thumbnailFileUrl": "***"
}
}
],
"pagination": {
"totalItemCount": 1
}
}
}
Hi, I was using Autowrapper. Some contents breaking my json schema.
I am getting this issue. An error occured deserializing the response.
I used [AutoWrapIgnore] everything goes well. But AutoWrapper not worked for me.
var jsonString = JsonSerializer.Serialize(models); //using with system.text.json (valid json)
my configurations
this response with autowrapper. json schema breaked