{"record":{"id":"3bf784b9f7181a8e","repo":"stride3d/stride","slug":"aliases-are-not-supported-in-json","errorCode":null,"errorMessage":"Aliases are not supported in JSON","messagePattern":"Aliases are not supported in JSON","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Serialization/JsonEventEmitter.cs","lineNumber":59,"sourceCode":"// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nusing System;\n\nnamespace Stride.Core.Yaml.Serialization\n{\n    internal sealed class JsonEventEmitter : ChainedEventEmitter\n    {\n        public JsonEventEmitter(IEventEmitter nextEmitter)\n            : base(nextEmitter)\n        {\n        }\n\n        public override void Emit(AliasEventInfo eventInfo)\n        {\n            throw new NotSupportedException(\"Aliases are not supported in JSON\");\n        }\n\n        public override void Emit(ScalarEventInfo eventInfo)\n        {\n            eventInfo.IsPlainImplicit = true;\n            eventInfo.Style = ScalarStyle.Plain;\n\n            var typeCode = eventInfo.SourceValue != null\n                ? Type.GetTypeCode(eventInfo.SourceType)\n                : TypeCode.Empty;\n\n            switch (typeCode)\n            {\n                case TypeCode.String:\n                case TypeCode.Char:\n                    eventInfo.Style = ScalarStyle.DoubleQuoted;\n                    break;\n                case TypeCode.Empty:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Serialization/JsonEventEmitter.cs#L41-L77","documentation":"JsonEventEmitter overrides Emit(AliasEventInfo) to throw NotSupportedException because the JSON format has no concept of anchors/aliases. Serializing an object graph that contains the same object instance referenced twice (which the YAM serializer would emit as an anchor+alias) cannot be represented in JSON by this emitter.","triggerScenarios":"Calling Serializer.Serialize with a JSON emitter on an object graph containing a reference cycle or a shared/duplicated object instance that triggers alias emission.","commonSituations":"Serializing parent/child or DAG-shaped object models (same object referenced from two properties) to JSON; graph cycles after switching output format from YAML to JSON.","solutions":["Remove duplicate/cyclic references from the graph (use DTO copies) before serializing to JSON","Serialize to YAML instead, which supports anchors and aliases","Configure the serializer to disable reference/alias emission (preserve-references off) so shared instances are serialized by value","Deep-copy shared sub-objects so each is an independent instance"],"exampleFix":"// before\nvar dto = new Dto(); dto.Inner = shared; dto.Other = shared; // alias emitted\nserializer.Serialize(jsonEmitter, dto);\n// after\ndto.Other = new Inner(shared.Value); // independent copy, no alias","handlingStrategy":"try-catch","validationCode":"// detect shared references that would require aliases\nvar seen = new HashSet<object>();\nbool hasShared = Visit(graph, o => o is { } x && !x.GetType().IsValueType && !seen.Add(x));","typeGuard":null,"tryCatchPattern":"try { serializer.Serialize(jsonEmitter, graph, type); }\ncatch (NotSupportedException) { throw new InvalidOperationException(\"Graph contains shared/cyclic references; use YAML or copy sub-objects\"); }","preventionTips":["Design JSON-serialized DTOs as strict trees (no shared instances)","Break cycles before serializing (parent references nulled, IDs instead)","Use YAML when aliasing/preserve-references is required","Document that JsonEventEmitter does not support aliases"],"tags":["json","yaml","serialization","aliases"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}