Anuken/Mindustry · error · SerializationException
Expecting an object, but found: '${jsonMap}'
Error message
Expecting an object, but found: '${jsonMap}' What it means
ContentParser.readFields expects a JSON object (a map of name/value pairs) so it can map each child onto a reflective field of the target object. If the supplied JsonValue is an array, string, number, or bool, it cannot be iterated as fields and a SerializationException is thrown.
Source
Thrown at core/src/mindustry/mod/ContentParser.java:1269
if(!field.field.isAnnotationPresent(Nullable.class) && field.field.get(object) == null && !implicitNullable.contains(field.field.getType())){
throw new RuntimeException("'" + field.field.getName() + "' in " +
((object.getClass().isAnonymousClass() ? object.getClass().getSuperclass() : object.getClass()).getSimpleName()) +
" is missing! " + object + "." + field.field.getName() + " cannot be null.");
}
}catch(Exception e){
throw new RuntimeException(e);
}
});
}
private void readFields(Object object, JsonValue jsonMap, boolean stripType){
if(stripType) jsonMap.remove("type");
readFields(object, jsonMap);
}
void readFields(Object object, JsonValue jsonMap){
if(!jsonMap.isObject()) throw new SerializationException("Expecting an object, but found: '" + jsonMap + "'");
JsonValue research = jsonMap.remove("research");
toBeParsed.remove(object);
var type = object.getClass();
var fields = parser.getFields(type);
for(JsonValue child = jsonMap.child; child != null; child = child.next){
FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));
if(metadata == null){
if(ignoreUnknownFields){
warn("@Unknown field '@' for class '@'", currentContent == null ? "" : "[" + currentContent.minfo.sourceFile.name() + "]: ", child.name, type.getSimpleName());
continue;
}else{
SerializationException ex = new SerializationException("Field not found: " + child.name + " (" + type.getName() + ")");
ex.addTrace(child.trace());
throw ex;
}
}
Field field = metadata.field;View on GitHub (pinned to f695ad7e60)
Solutions
- Inspect the reported jsonMap value and confirm the surrounding field expects an object.
- Rewrite the JSON node as an object literal { ... }.
- Check the field type in the target class — if it expects a collection, the object-vs-array shape may be inverted.
- Enable ignoreUnknownFields/logging to see which parent field led here.
Example fix
// before (array where object expected)
"requirements": [ ["copper", 10] ]
// after (object form the parser expects)
"requirements": { "copper": 10 } Defensive patterns
Strategy: validation
Validate before calling
// Confirm a JsonValue is an object before reading fields.
if(jsonMap == null || !jsonMap.isObject()) {
throw new IllegalArgumentException("Expected JSON object, got: " + (jsonMap == null ? "null" : jsonMap.type()));
} Type guard
boolean isJsonObject(JsonValue v){ return v != null && v.isObject(); } Try / catch
try {
parser.readFields(obj, jsonMap);
} catch(SerializationException e) {
if(e.getMessage().startsWith("Expecting an object")) { /* fix JSON shape */ }
else throw e;
} Prevention
- Author nested content as objects ({}) unless a field explicitly expects an array.
- Lint mod JSON with a validator before loading.
- Cross-check each field's expected shape against the source class.
When it happens
Trigger: A mod JSON value that must be an object is instead an array or scalar — e.g. a block definition whose body is a list, or a nested content field resolved to a primitive. Reached whenever readFields(object, jsonMap) is called with a non-object JsonValue.
Common situations: Wrong JSON structure (array where object expected); copy-paste from a list-style example; inline content defined with [] instead of {}; a 'type' resolution that produced a non-object value.
Related errors
- Resolving arbitrary classes (${className}) is not allowed. U
- '${field.field.getName()}' in ${className} is missing! ${obj
- Error accessing field: ${field.getName()} (${type.getName()}
- Attribute definitions must be objects, e.g. {heat: 10}
- Unknown status effect: '
AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14).
Data as JSON: /api/errors/e5dd1a0c2ca141a3.
Report an issue: GitHub.