GithubHelp home page GithubHelp logo

Comments (4)

j82w avatar j82w commented on June 15, 2024 1

Hi devcrp,

Thanks for the repo code. I was able to reproduce the issue. I was using a .net core application and you were using .net framework. It works fine in .net core, but is broken in .net framework. The issue will be fixed in the next release which will hopefully happen soon., For now you can do the following workaround.

        public static async Task<string> Insert(Person person)
        {
            using (var cosmosClient = new CosmosClient(new CosmosConfiguration(ENDPOINT, KEY).UseCustomJsonSerializer(new CustomJsonSerializer())))
            {
                var container = cosmosClient.Databases[DB].Containers[CONTAINER];
                var response = await container.Items.CreateItemAsync(person.id, person);
                return JsonConvert.SerializeObject(person);
            }
        }

        public static async Task<Person> Get(string id)
        {
            using (var cosmosClient = new CosmosClient(new CosmosConfiguration(ENDPOINT, KEY).UseCustomJsonSerializer(new CustomJsonSerializer())))
            {
                var container = cosmosClient.Databases[DB].Containers[CONTAINER];
                CosmosItemResponse<Person> result = await container.Items.ReadItemAsync<Person>(id, id: id);
                return result.Resource;
            }
        }

        /// <summary>
        /// The default Cosmos JSON serializer
        /// </summary>
        internal class CustomJsonSerializer : CosmosJsonSerializer
        {
            private static readonly JsonSerializer Serializer = new JsonSerializer();
            private static readonly Encoding DefaultEncoding = new UTF8Encoding(false, true);

            public override T FromStream<T>(Stream stream)
            {
                using (stream)
                {
                    if (typeof(Stream).IsAssignableFrom(typeof(T)))
                    {
                        return (T)(object)(stream);
                    }

                    using (StreamReader sr = new StreamReader(stream))
                    {
                        using (JsonTextReader jsonTextReader = new JsonTextReader(sr))
                        {
                            return CustomJsonSerializer.Serializer.Deserialize<T>(jsonTextReader);
                        }
                    }
                }
            }

            public override Stream ToStream<T>(T input)
            {
                MemoryStream streamPayload = new MemoryStream();
                using (StreamWriter streamWriter = new StreamWriter(streamPayload, encoding: CustomJsonSerializer.DefaultEncoding, bufferSize: 1024, leaveOpen: true))
                {
                    using (JsonWriter writer = new JsonTextWriter(streamWriter))
                    {
                        writer.Formatting = Newtonsoft.Json.Formatting.None;
                        CustomJsonSerializer.Serializer.Serialize(writer, input);
                        writer.Flush();
                        streamWriter.Flush();
                    }
                }

                streamPayload.Position = 0;
                return streamPayload;
            }
        }

from azure-cosmos-dotnet-v3.

j82w avatar j82w commented on June 15, 2024

Hi devcrp,

I was not able to repo the issue. I created the item via the SDK and viewed it in the portal data explorer and it appears fine.

dynamic test = new { id = "newid", name = "Román", AccountNumber = "1234890" };
var response = await container.Items.CreateItemAsync(test.AccountNumber, test);

image

What are you using to view the inserted item? When you read the item back via the SDK is it still correct? Can you provide a link to a github repository with the repo?

from azure-cosmos-dotnet-v3.

devcrp avatar devcrp commented on June 15, 2024

Hi j82w,

Here's the test project where I can reproduce the issue: https://github.com/devcrp/CosmosDBvsDiacritics
In this case I'm using the cosmosDB emulator to test it locally, but the result is the same when using the CosmosDB in the Azure server.

Also, here's where I'm viewing the inserted item
image

And this is the container's config in case it helps
image

from azure-cosmos-dotnet-v3.

devcrp avatar devcrp commented on June 15, 2024

That did it, thank you!!

from azure-cosmos-dotnet-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.