{"record":{"id":"94a8efc1299fc6a6","repo":"emberjs/ember.js","slug":"defining-a-custom-serialize-method-on-an-engine-ro","errorCode":null,"errorMessage":"Defining a custom serialize method on an Engine route is not supported.","messagePattern":"Defining a custom serialize method on an Engine route is not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@ember/routing/router.ts","lineNumber":421,"sourceCode":"\n        if (!route) {\n          // SAFETY: this is configured in `commonSetupRegistry` in the\n          // `@ember/application/lib` package.\n          let DefaultRoute: any = routeOwner.factoryFor('route:basic')!.class;\n          routeOwner.register(fullRouteName, class extends DefaultRoute {});\n          route = routeOwner.lookup(fullRouteName) as Route;\n\n          if (DEBUG) {\n            if (router.namespace.LOG_ACTIVE_GENERATION) {\n              info(`generated -> ${fullRouteName}`, { fullName: fullRouteName });\n            }\n          }\n        }\n\n        route._setRouteName(routeName);\n\n        if (engineInfo && !hasDefaultSerialize(route)) {\n          throw new Error(\n            'Defining a custom serialize method on an Engine route is not supported.'\n          );\n        }\n\n        return route;\n      }\n\n      getSerializer(name: string) {\n        let engineInfo = router._engineInfoByRoute[name];\n\n        // If this is not an Engine route, we fall back to the handler for serialization\n        if (!engineInfo) {\n          return;\n        }\n\n        return engineInfo.serializeMethod || defaultSerialize;\n      }\n","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@ember/routing/router.ts#L403-L439","documentation":"When the router resolves a route that belongs to an engine (route has engineInfo), the route must use the engine's default serialization. A custom serialize method defined on an Engine route conflicts with how engine routes serialize their models, so Router#getRoute throws.","triggerScenarios":"Defining serialize(model) in an engine's route class (or serializeMethod) and then navigating/looking up that route through getRoute when engineInfo is present and hasDefaultSerialize(route) is false.","commonSituations":"Migrating a standard route with a custom serialize hook into an engine; addons that add serialize hooks to routes that later get mounted inside engines.","solutions":["Remove the custom serialize method from the engine route","Handle serialization in the parent app's route that mounts the engine","Use the default dynamic segment serialization expected by the engine's route map"],"exampleFix":"// before (engine route)\nexport default class PostRoute extends Route {\n  serialize(model) { return { slug: model.slug }; }\n}\n// after\nexport default class PostRoute extends Route {} // rely on default serialize / parent route","handlingStrategy":"validation","validationCode":"if (routeInfo.engineInfo && typeof route.serialize === 'function' && !hasDefaultSerialize(route)) {\n  throw new Error('Engine routes cannot define custom serialize');\n}","typeGuard":"function isEngineRouteWithoutCustomSerialize(route) { return !route.serialize || route.serialize === Route.prototype.serialize; }","tryCatchPattern":"try { route = router.getRoute(name); } catch (e) { if (/custom serialize method on an Engine route/.test(e.message)) { route = getRouteWithoutSerialize(name); } else throw e; }","preventionTips":["Never define serialize in engine route classes","Let the parent app own serialization for mounted engines","When migrating routes into engines, strip custom serialize hooks first"],"tags":["ember","routing","engines","serialize","router"],"backgroundTag":"engine-route-serialize-unsupported","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}