quarkusio/quarkus · error · IllegalStateException
Type {type} should be handled by the switch
Error message
Type {type} should be handled by the switch What it means
JacksonSerializationUtils.getDefaultValue generates bytecode that yields a type's default value (0, false, etc.) when a JSON node is null. It switches over primitive type names (byte?, char, double, float, int, long, short, boolean...); any type that reaches it outside the covered set throws IllegalStateException. This is a build/deployment-time failure of Quarkus's generated Jackson serializer/deserializer machinery, i.e. an internal coverage gap rather than a documented user API.
Source
Thrown at extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonSerializationUtils.java:63
// to context.readTreeAsValue() which performs proper type validation.
return false;
}
static ResultHandle getDefaultValue(BytecodeCreator bytecodeCreator, Type type) {
if (type.kind() != Kind.PRIMITIVE) {
return bytecodeCreator.loadNull();
}
return switch (type.name().toString()) {
case "byte" -> bytecodeCreator.load(DEFAULT_BYTE);
case "boolean" -> bytecodeCreator.load(DEFAULT_BOOLEAN);
case "char" -> bytecodeCreator.load(DEFAULT_CHAR);
case "double" -> bytecodeCreator.load(DEFAULT_DOUBLE);
case "float" -> bytecodeCreator.load(DEFAULT_FLOAT);
case "int" -> bytecodeCreator.load(DEFAULT_INT);
case "long" -> bytecodeCreator.load(DEFAULT_LONG);
case "short" -> bytecodeCreator.load(DEFAULT_SHORT);
default -> throw new IllegalStateException("Type " + type + " should be handled by the switch");
};
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Change the offending field type to one supported by the switch (int, long, short, char, float, double, boolean, String, wrappers)
- Avoid the generated code path by using standard Jackson annotations/deserializers for that DTO field
- Check the Quarkus version and changelog; if a common primitive (e.g. byte) fails, file a Quarkus bug with a reproducer
- Isolate the DTO and test compilation with -Dquickly to confirm which field triggers the gap
Example fix
// before
class Dto { private byte status; }
// after
class Dto { private int status; } Defensive patterns
Strategy: validation
Validate before calling
Set<String> supported = Set.of("char","double","float","int","long","short","boolean");
for (Field f : Dto.class.getDeclaredFields()) {
if (f.getType().isPrimitive() && !supported.contains(f.getType().getName()))
throw new IllegalStateException("Primitive field " + f + " lacks a generated default value");
} Type guard
static boolean isSupportedPrimitive(Class<?> c) {
return c.isPrimitive() && !c.equals(byte.class) && !c.equals(void.class);
} Try / catch
try {
buildApplication();
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Type ")) {
// switch that DTO to standard Jackson handling
}
} Prevention
- Avoid byte primitives in DTOs handled by generated serializers
- Prefer wrapper types (Integer, Long) over primitives for exotic fields
- Rebuild the whole app after Quarkus upgrades
- Centralize DTO field types to a reviewed set
When it happens
Trigger: A primitive-typed field whose default value must be generated is not covered by the switch (e.g. byte fields, or a new primitive path added upstream), reached while generating deserializer bytecode for a DTO class.
Common situations: DTOs with byte/byte[] or exotic primitive fields processed by the generated serializer; Quarkus upgrades exposing new paths; inconsistent switch coverage between getDefaultValue and its callers (e.g. JacksonDeserializerFactory).
Related errors
- Name cannot start with '/':${name}
- 'quarkus-narayana-lra' can only work if 'quarkus-rest-jackso
- Type {fieldType} should be handled by the switch
- Parameter type '<type>' is not supported for method '<method
- Failed to open path tree with root %s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/2c6c518ec9019eb0.
Report an issue: GitHub.