Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStorage SaveObject leaves characters #309

Closed
garcipat opened this issue Sep 12, 2024 · 2 comments
Closed

FileStorage SaveObject leaves characters #309

garcipat opened this issue Sep 12, 2024 · 2 comments
Assignees

Comments

@garcipat
Copy link
Contributor

When I'm Serializing an object with SaveObjectAsync in a folder where there alrady has been an object serialized, there are leftover characters. The existing content is not cleared.

Example:
First Serializing output:

{"IsAutomaticExportEnabled":true,"DataProvisioning":"DataPointsOnly","SamplingInterval":2}

Second serialization:

{"IsAutomaticExportEnabled":true,"DataProvisioning":"Sampling","SamplingInterval":2}**al":2}**
``

there are leftovers at the end becasue the previous opbject used more characters. Deserializing afterwards crashes then.

Tested with Version 10.7.1 and also the new 11.0.2
Tested with FolderStorage
@niemyjski
Copy link
Member

Thanks for reporting this issue, can you please provide a failing test and if a or would be grateful.

@garcipat
Copy link
Contributor Author

garcipat commented Sep 12, 2024

Of course:

public class FileStorageTests
{
    [Fact]
    public async Task SaveObject_ShouldSaveObjectClean()
    {
        using var storage = new FolderFileStorage(new FolderFileStorageOptions() { Folder = "Output" });
        var file = $"test-{Random.Shared.Next()}.json";
        var longTextInstance = new TestClass
        {
            TestProperty = "VeryLongString"
        };

        var shortTextInstance = new TestClass
        {
            TestProperty = "Short"
        };

        await storage.SaveObjectAsync(file, longTextInstance);
        await storage.SaveObjectAsync(file, shortTextInstance);

        var storedTestClass = await storage.GetObjectAsync<TestClass>(file);
    }

    public class TestClass
    {
        public required string TestProperty { get; set; }
    }
}

I have not tested it with other implementations. As a workaround im deleting the existing file before writing the same again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants