json-path/JsonPath · error · MappingException
Unable to find no-arg ctr for " + className
Error message
Unable to find no-arg ctr for " + className
What it means
newNoArgInstance() reflectively instantiates a concrete class found while building a target collection (and other databind targets) by scanning its public constructors for a zero-argument one. If the class has no public no-arg constructor, or only interfaces were found, it throws MappingException "Unable to find no-arg ctr for <ClassName>". JSON-P/JSON-B style databinding requires bean-style types that can be created empty and then populated.
Source
Thrown at json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java:340
* @throws MappingException if no-arg public constructor is not there
*/
private Object newNoArgInstance(Class<?> targetType) throws MappingException {
if (targetType.isInterface()) {
return null;
} else {
for (Constructor<?> ctr : targetType.getConstructors()) {
if (ctr.getParameterCount() == 0) {
try {
return ctr.newInstance();
} catch (ReflectiveOperationException e) {
throw new MappingException(e);
} catch (IllegalArgumentException e) {
// never happens
}
}
}
String className = targetType.getSimpleName();
throw new MappingException("Unable to find no-arg ctr for " + className);
}
}
/**
* Locates optional API method on the supplied JSON-B API implementation class with
* the supplied name and parameter types. Searches the superclasses up to
* {@code Object}, but ignores interfaces and default interface methods. Returns
* {@code null} if no {@code Method} can be found.
*
* @param clazz the implementation class to reflect upon
* @param name the name of the method
* @param paramTypes the parameter types of the method
* @return the {@code Method} reference, or {@code null} if none found
*/
private Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
while (clazz != null && !clazz.isInterface()) {
for (Method method : clazz.getDeclaredMethods()) {
final int mods = method.getModifiers();
View on GitHub (pinned to 62a4c9f0f6)
Solutions
- Add a public no-arg constructor to the target class (and standard getters/setters so databinding can populate it).
- Use a type the provider can construct: java.util.LinkedList/ArrayList/LinkedHashSet instead of a custom collection class.
- If you cannot modify the class, read into Map<String,Object> / List<Object> and construct your type manually.
- For Lombok, add @NoArgsConstructor(access = AccessLevel.PUBLIC) alongside @Builder.
Example fix
// before
@Builder
class Book { private String title; } // MappingException: Unable to find no-arg ctr for Book
// after
@Builder
@NoArgsConstructor
@AllArgsConstructor
class Book { private String title; } Defensive patterns
Strategy: validation
Validate before calling
static boolean databindable(Class<?> t) {
try {
t.getConstructor();
return true;
} catch (NoSuchMethodException e) {
return false;
}
} Try / catch
try {
return jsonPath.read(path, MyDto.class);
} catch (MappingException e) {
return objectMapper.convertValue(jsonPath.read(path, Map.class), MyDto.class);
} Prevention
- Give every databind target a public no-arg constructor and bean setters.
- With Lombok @Builder, always add @NoArgsConstructor and @AllArgsConstructor.
- Avoid non-static inner classes as mapping targets.
- Keep target classes top-level and mutable for provider compatibility.
When it happens
Trigger: Mapping a JSON array into a concrete collection class lacking a public no-arg constructor (e.g. a custom ImmutableList extends AbstractList with only (Collection) ctor), or mapping to a POJO element/collection type without a default constructor, via read(path, Type.class) or TypeRef on JakartaMappingProvider.
Common situations: Immutable/value classes and builder-pattern DTOs; Lombok @Builder without @NoArgsConstructor; inner (non-static) classes whose constructors require an enclosing instance; classes with only parameterized constructors added after a refactor.
Related errors
- Use map() method to databind a JsonObject
- JSON path [%s] doesn't match. Expected: %s Actual: %s
- JSON Assert Error: %s Expected: %s Actual: %s
- Document contains the path <%s> but was expected not to.
- No type info in TypeRef
AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11).
Data as JSON: /api/errors/dd52d31edc05b855.
Report an issue: GitHub.