quarkusio/quarkus · error · RuntimeException
Type ${type} not managed
Error message
Type ${type} not managed What it means
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.
Source
Thrown at integration-tests/mongodb-client/src/main/java/io/quarkus/it/mongodb/discriminator/jsonb/VehicleDeserializer.java:25
import jakarta.json.bind.serializer.JsonbDeserializer;
import jakarta.json.stream.JsonParser;
import io.quarkus.it.mongodb.discriminator.Car;
import io.quarkus.it.mongodb.discriminator.Moto;
import io.quarkus.it.mongodb.discriminator.Vehicle;
public class VehicleDeserializer implements JsonbDeserializer<Vehicle> {
@Override
public Vehicle deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
JsonObject json = parser.getObject();
String type = json.getString("type");
switch (type) {
case "CAR":
return new Car(type, json.getString("name"), json.getInt("seatNumber"));
case "MOTO":
return new Moto(type, json.getString("name"), json.getBoolean("sideCar"));
default:
throw new RuntimeException("Type " + type + " not managed");
}
}
}
View on GitHub (pinned to e1c734241f)
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
Example fix
// before
switch (type) {
case "CAR": return new Car(...);
case "MOTO": return new Moto(...);
default: throw new RuntimeException("Type " + type + " not managed");
}
// after
switch (type) {
case "CAR": return new Car(...);
case "MOTO": return new Moto(...);
case "TRUCK": return new Truck(type, json.getString("name"), json.getInt("payload"));
default: throw new RuntimeException("Type " + type + " not managed");
} Defensive patterns
Strategy: validation
Validate before calling
String type = json.getString("type");
if (!"CAR".equals(type) && !"MOTO".equals(type)) {
throw new JsonbException("Unsupported vehicle type: " + type);
} Type guard
boolean isKnownVehicleType(String type) {
return "CAR".equals(type) || "MOTO".equals(type);
} Try / catch
try {
Vehicle v = jsonb.fromJson(payload, Vehicle.class);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("not managed")) {
log.warnf("Skipping document with unmanaged discriminator: %s", e.getMessage());
} else {
throw e;
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to deserialize the dev mode context. Does the Quarkus
- Could not deserialize the provided message.
- Don't know how to get event data (dataContentType: '%s', jav
- Cannot deserialize data for data-content-encoding: '${dataCo
- Don't know how to get event data (dataContentType: '%s', jav
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/852b066bb1eb7714.
Report an issue: GitHub.