Java.lang.IllegalArgumentException: No se ha encontrado ningún convertidor para el valor devuelto del tipo


Con este código

@RequestMapping(value = "/bar/foo", method = RequestMethod.GET)
    public ResponseEntity<foo> foo() {

        Foo model;
        ...
        return ResponseEntity.ok(model);
    }
}

Obtengo la siguiente excepción

java.lang.IllegalArgumentException: No converter found for return value of type

Mi conjetura es que el objeto no se puede convertir a JSON porque falta Jackson. No entiendo por qué porque pensé que Jackson estaba construido con Spring boot.

Entonces he tratado de añadir Jackson al pom.xml pero todavía tengo el mismo error

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.4.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.3</version>
</dependency>

¿Tengo que cambiar las propiedades de arranque de resorte para que esto funcione?

Gracias

Author: Marc, 2016-06-15

9 answers

El problema era que uno de los objetos anidados en Foo no tenía ningún getter/setter

 114
Author: Marc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-15 17:55:45

Agregue la siguiente dependencia a su pom.xml:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.8.1</version>
</dependency>
 11
Author: Prateek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-22 19:26:07

Utilizar @ResponseBody y getter/setter. Espero que resuelva su problema.

@RequestMapping(value = "/bar/foo", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<foo> foo() {

Y actualizar su mvc-dispatcher-servlet.xml:

<mvc:annotation-driven>
     <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
   </mvc:message-converters>
</mvc:annotation-driven>
 4
Author: SkyWalker,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-15 17:00:46

Tuve el mismo problema, y desafortunadamente no se pudo resolver agregando métodos getter o agregando dependencias Jackson.

Luego miré la Guía Oficial de Primavera, y seguí su ejemplo como se da aquí - https://spring.io/guides/gs/actuator-service / - donde el ejemplo también muestra la conversión del objeto devuelto al formato JSON.

Luego hice mi propio proyecto, con la diferencia de que esta vez también agregué las dependencias y construí plugins eso está presente en el pom.archivo xml del ejemplo oficial de la Guía de Primavera que mencioné anteriormente.

Las dependencias modificadas y la parte de compilación del archivo XML se ven así!

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Puede ver lo mismo en el enlace mencionado anteriormente.

Y mágicamente, al menos para mí, funciona. Por lo tanto, si ya ha agotado sus otras opciones, es posible que desee probar esto, como fue el caso conmigo.

Solo una nota al margen, no funcionó para mí cuando agregué el dependencias en mi proyecto anterior e hizo Maven instalar y actualizar cosas del proyecto. Así que tuve que volver a hacer mi proyecto desde cero. No me molesté mucho al respecto, ya que el mío es un proyecto de ejemplo, pero es posible que desee buscar eso también!

 3
Author: thisisashwani,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-09 10:08:24

El problema ocurrió en mi caso porque Spring framework no pudo obtener las propiedades de los objetos anidados. Getters / Setters es una forma de resolver. Hacer públicas las propiedades es otra solución rápida y sucia para validar si este es el problema.

 1
Author: vish213,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-07 10:28:18

Agregue el getter/setter que falta dentro del bean mencionado en el mensaje de error.

 1
Author: Soumyajit Swain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-25 07:22:51

También experimenté ese error cuando por accidente puse dos @ JsonProperty("some_value") líneas idénticas en diferentes propiedades dentro de la clase

 0
Author: Vit Ias,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-13 08:57:44

Me enfrenté al mismo problema durante mucho tiempo, luego llego a saber que tengo que convertir el objeto en JSON usando Object Mapper y pasarlo como JSON Object

    @RequestMapping(value = "/getTags", method = RequestMethod.GET)
    public @ResponseBody
    String getTags(@RequestParam String tagName) throws 
    JsonGenerationException, JsonMappingException, IOException {
    List<Tag> result = new ArrayList<Tag>();
    for (Tag tag : data) {if (tag.getTagName().contains(tagName)) {
            result.add(tag);
        }
    }
    ObjectMapper objectMapper = new ObjectMapper();
    String json = objectMapper.writeValueAsString(result);
    return json;
    }
 0
Author: Kiran Kawade,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-05 06:26:50

En mi caso, olvidé agregar la biblioteca jackson-core.jar, solo agregué anotaciones de Jackson.jar y Jackson-databind.frasco. Cuando agregué Jackson-core.jar, arregló el problema.

 0
Author: Lisa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-20 18:56:52