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

Mesh Extras not supporting custom encodersettings, to avoid special character serialization #233

Open
msusag opened this issue May 6, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@msusag
Copy link

msusag commented May 6, 2024

Hi, and thanks for developing this nice GLTF library for .NET!

When storing JSON information (or any other information with quotation and other special characters), in the mesh.Extras element,
the special characters in the JSON data is escaped and stored in the output .glb files.

In 1.0.0-alpha0030, special characters were not escaped.
In that previous version we were able to store for example
{"key":123456}
directly in the output glb files without any escaping. Our reader accepts data in this format only.

With the new System.Text.Json serializer used in the current latest version 1.0.0-alpha0031, characters are escaped (due to System.Text.Json default encoder settings.

So the data stored in the .glb file is now
{\u0022key\u0022:123456}

We have found no way with SharpGLTF 1.0.0-alpha0031 be able to override the json encoder settings, to make it store quotes in text without escaping, in output .glb files.

We understand the reasons for escaping is to avoid potential security issues, but in this case the added information is system controlled, not provided by end users.

Would it be possible to override the jsonSerializerOptions and encoderSettings for the JSONEXTRAS (System.Text.Json) in
https://github.com/vpenades/SharpGLTF/blob/master/src/SharpGLTF.Core/Schema2/gltf.ExtraProperties.cs#L19

It should be possible to use custom JsonSerializerOptions and encoderSettings for the JSONEXTRAS instance, as documented in
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/character-encoding#serialize-specific-characters

  • OS: Linux
  • SharpGLTF Version 1.0.0-alpha0031
@msusag msusag added the bug Something isn't working label May 6, 2024
@msusag msusag changed the title Mesh Extras Mesh Extras not supporting custom encodersettings, to avoid special character serialization May 6, 2024
@vpenades
Copy link
Owner

vpenades commented Jun 5, 2024

I have't been able to reproduce this.

Are you sure you're passing a proper json nodes document to the extras?

The only way I can think of to reproduce your issue is to pass the entire json as a string inside a Json Value Node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants