{"record":{"id":"852b066bb1eb7714","repo":"quarkusio/quarkus","slug":"type-type-not-managed","errorCode":null,"errorMessage":"Type ${type} not managed","messagePattern":"Type (.+?) not managed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/discriminator/jsonb/VehicleDeserializer.java","lineNumber":25,"sourceCode":"import jakarta.json.bind.serializer.JsonbDeserializer;\nimport jakarta.json.stream.JsonParser;\n\nimport io.quarkus.it.mongodb.discriminator.Car;\nimport io.quarkus.it.mongodb.discriminator.Moto;\nimport io.quarkus.it.mongodb.discriminator.Vehicle;\n\npublic class VehicleDeserializer implements JsonbDeserializer<Vehicle> {\n    @Override\n    public Vehicle deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {\n        JsonObject json = parser.getObject();\n        String type = json.getString(\"type\");\n        switch (type) {\n            case \"CAR\":\n                return new Car(type, json.getString(\"name\"), json.getInt(\"seatNumber\"));\n            case \"MOTO\":\n                return new Moto(type, json.getString(\"name\"), json.getBoolean(\"sideCar\"));\n            default:\n                throw new RuntimeException(\"Type \" + type + \" not managed\");\n        }\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":29,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/discriminator/jsonb/VehicleDeserializer.java#L7-L29","documentation":"VehicleDeserializer is a custom JSON-B deserializer for the polymorphic Vehicle type. It reads the 'type' field from the incoming JSON and, in a switch, constructs either a Car or a Moto. If the discriminator value is anything else, it throws RuntimeException('Type ' + type + ' not managed'), meaning the JSON document carries a discriminator the deserializer was never written to handle.","triggerScenarios":"Deserializing (via Jsonb.fromJson or the MongoDB POJO codec path using this Jsonb deserializer) a JSON document whose 'type' field is not exactly 'CAR' or 'MOTO' — e.g. 'TRUCK', 'car' (lowercase), or a missing type yielding null.","commonSituations":"Adding a new Vehicle subclass in the entity model without extending the deserializer's switch; legacy documents written by an older schema version; case-mismatched discriminators; documents written directly into MongoDB by another tool with a different type value.","solutions":["Ensure the JSON 'type' field is exactly 'CAR' or 'MOTO' (uppercase, no whitespace)","Add a new case to the switch in VehicleDeserializer for any newly introduced vehicle type","Inspect the offending document in MongoDB (db.collection.findOne) to see the actual type value","Normalize/validate the discriminator before deserialization, or throw a descriptive JsonbException with the document id"],"exampleFix":"// before\nswitch (type) {\n    case \"CAR\": return new Car(...);\n    case \"MOTO\": return new Moto(...);\n    default: throw new RuntimeException(\"Type \" + type + \" not managed\");\n}\n// after\nswitch (type) {\n    case \"CAR\": return new Car(...);\n    case \"MOTO\": return new Moto(...);\n    case \"TRUCK\": return new Truck(type, json.getString(\"name\"), json.getInt(\"payload\"));\n    default: throw new RuntimeException(\"Type \" + type + \" not managed\");\n}","handlingStrategy":"validation","validationCode":"String type = json.getString(\"type\");\nif (!\"CAR\".equals(type) && !\"MOTO\".equals(type)) {\n    throw new JsonbException(\"Unsupported vehicle type: \" + type);\n}","typeGuard":"boolean isKnownVehicleType(String type) {\n    return \"CAR\".equals(type) || \"MOTO\".equals(type);\n}","tryCatchPattern":"try {\n    Vehicle v = jsonb.fromJson(payload, Vehicle.class);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"not managed\")) {\n        log.warnf(\"Skipping document with unmanaged discriminator: %s\", e.getMessage());\n    } else {\n        throw e;\n    }\n}","preventionTips":["Whenever a new Vehicle subclass is added, update VehicleDeserializer's switch in the same commit","Store discriminators in a canonical uppercase form and normalize input before switching","Add a round-trip test deserializing every known vehicle type","Enumerate supported types in a single enum/constant set shared by the deserializer"],"tags":["jsonb","deserialization","mongodb","polymorphism"],"backgroundTag":"unknown-discriminator-value","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}