Skip to content

Improve TypeFactory.constructFromCanonical() to work with `java.lang.reflect.Type.getTypeName()' format #1768

@luiscleto

Description

@luiscleto

Java's Type#getTypeName() for parameterized types with multiple type parameters returns the inner types in a comma and space separated list. (e.g. "java.util.Map<java.lang.Integer, java.lang.Double>").

Attempting to construct the type using TypeFactory's constructFromCanonical will result in an exception as the inner tokens are not trimmed (although the top level String is). For the example above it would be

java.lang.IllegalArgumentException: Failed to parse type 'java.util.Map<java.lang.Integer, java.lang.Double>' (remaining: '>'): Can not locate class ' java.lang.Double', problem:  java.lang.Double
	at com.fasterxml.jackson.databind.type.TypeParser._problem(TypeParser.java:87)
	at com.fasterxml.jackson.databind.type.TypeParser.findClass(TypeParser.java:81)
	at com.fasterxml.jackson.databind.type.TypeParser.parseType(TypeParser.java:44)
	at com.fasterxml.jackson.databind.type.TypeParser.parseTypes(TypeParser.java:62)
	at com.fasterxml.jackson.databind.type.TypeParser.parseType(TypeParser.java:49)
	at com.fasterxml.jackson.databind.type.TypeParser.parse(TypeParser.java:30)
	at com.fasterxml.jackson.databind.type.TypeFactory.constructFromCanonical(TypeFactory.java:236)

Since using Jackson's own JavaTypes to obtain the canonical form does not yield inner spaces, no error will occur for that scenario, hence I see this as a feature I'd like to have rather than a bug. This could be easily achieved if findClass trimmed the String it receives (or received an already trimmed token).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions