Error consuming REST Java Arraylist<String>

Asked

Viewed 137 times

0

I have a Maven web application in Netbeans running on Glassfish 4.1.1, and a basic CRUD class has been created to receive and return in JSON format, but when a CRUD will be returned List<String> the server shows an error:

Grave: Messagebodywriter not found for media type=text/Plain, type=class java.util.Arraylist, genericType=java.util.List.

Below goes Glassfish server log

 
Launching GlassFish on Felix platform
out 27, 2016 5:59:15 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner createBundleProvisioner
INFORMAÇÕES: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
out 27, 2016 5:59:15 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
ADVERTÊNCIA: Skipping entry  because it is not an absolute URI.
out 27, 2016 5:59:15 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner$DefaultCustomizer getLocations
ADVERTÊNCIA: Skipping entry  because it is not an absolute URI.
out 27, 2016 5:59:16 PM com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner startBundles
ADVERTÊNCIA: Can not start bundle file:/C:/Program%20Files/glassfish-4.1.1/glassfish/modules/core.jar because it is not contained in the list of installed bundles.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@6200c9d8 in service registry.
LogManagerService.postConstruct : rootFolder=C:\Program Files\glassfish-4.1.1\glassfish
LogManagerService.postConstruct : templateDir=C:\Program Files\glassfish-4.1.1\glassfish\lib\templates
LogManagerService.postConstruct : src=C:\Program Files\glassfish-4.1.1\glassfish\lib\templates\logging.properties
LogManagerService.postConstruct : dest=C:\Users\Bruno\AppData\Roaming\NetBeans\8.1\config\GF_4.1.1\domain1\config\logging.properties
Informações:   Running GlassFish Version: GlassFish Server Open Source Edition  4.1.1  (build 1)
Informações:   Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter
Informações:   Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Informações:   Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Informações:   Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Informações:   Authorization Service has successfully initialized.
Informações:   Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
Informações:   JTS5014: Recoverable JTS instance, serverId = [100]
Advertência:   Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-1, realClassName=org.glassfish.grizzly.http2.Http2AddOn
Grave:   Application previously deployed is not at its original location any more: file:/D:/Dropbox/WebServiceSisInfo%20Savare/Codigo%20Fonte/WebserviceSisInfoSavare/build/web/
Informações:   Grizzly Framework 2.3.23 started in: 62ms - bound to [/0.0.0.0:8080]
Advertência:   Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-2, realClassName=org.glassfish.grizzly.http2.Http2AddOn
Informações:   Grizzly Framework 2.3.23 started in: 50ms - bound to [/0.0.0.0:8181]
Advertência:   Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=admin-listener, realClassName=org.glassfish.grizzly.http2.Http2AddOn
Informações:   Grizzly Framework 2.3.23 started in: 27ms - bound to [/0.0.0.0:4848]
Informações:   Grizzly Framework 2.3.23 started in: 21ms - bound to [/0.0.0.0:3700]
Informações:   visiting unvisited references
Informações:   Java security manager is disabled.
Informações:   Entering Security Startup Service.
Informações:   Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
Informações:   Security Service(s) started successfully.
Informações:   Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080
Informações:   Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Informações:   Created HTTP listener admin-listener on host/port 0.0.0.0:4848
Informações:   Created virtual server server
Informações:   Created virtual server __asadmin
Informações:   Setting JAAS app name glassfish-web
Informações:   Virtual server server loaded default web module 
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   WELD-000900: 2.2.13 (Final)
Informações:   HV000001: Hibernate Validator 5.1.2.Final
WARN:   WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
WARN:   WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN:   WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
Advertência:   Illegal character "/" at position 4 is not allowed as a part of a name in a path template "/{id/}".
Advertência:   The following warnings have been detected: WARNING: The (sub)resource method update in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method create in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method listChamados in com.savare.controllers.ChamadoController contains empty path annotation.
Informações:   Loading application [TesteSavareSisInfo-0.0.1] at [/TesteSavareSisInfo-0.0.1]
Informações:   Loading application TesteSavareSisInfo-0.0.1 done in 8.357 ms
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   Inicializando Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) para o contexto '/TesteSavareSisInfo'
Advertência:   Illegal character "/" at position 4 is not allowed as a part of a name in a path template "/{id/}".
Advertência:   The following warnings have been detected: WARNING: The (sub)resource method update in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method create in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method listChamados in com.savare.controllers.ChamadoController contains empty path annotation.
Informações:   Loading application [TesteSavareSisInfo] at [/TesteSavareSisInfo]
Informações:   Loading application TesteSavareSisInfo done in 2.315 ms
Informações:   GlassFish Server Open Source Edition  4.1.1  (1) startup time : Felix (11.775ms), startup services(11.656ms), total(23.431ms)
Informações:   Grizzly Framework 2.3.23 started in: 58ms - bound to [/0.0.0.0:7676]
Advertência:   Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-2, realClassName=org.glassfish.grizzly.http2.Http2AddOn
Informações:   Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Informações:   Grizzly Framework 2.3.23 started in: 38ms - bound to [/0.0.0.0:8181]
Advertência:   Instance could not be initialized. Class=interface org.glassfish.grizzly.http.server.AddOn, name=http-listener-1, realClassName=org.glassfish.grizzly.http2.Http2AddOn
Informações:   Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080
Informações:   Grizzly Framework 2.3.23 started in: 9ms - bound to [/0.0.0.0:8080]
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   Inicializando Mojarra 2.2.12 ( 20150720-0848 ://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) para o contexto '/TesteSavareSisInfo'
Advertência:   Illegal character "/" at position 4 is not allowed as a part of a name in a path template "/{id/}".
Advertência:   The following warnings have been detected: WARNING: The (sub)resource method update in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method create in com.savare.controllers.ChamadoController contains empty path annotation.
WARNING: The (sub)resource method listChamados in com.savare.controllers.ChamadoController contains empty path annotation.
Informações:   Loading application [TesteSavareSisInfo] at [/TesteSavareSisInfo]
Informações:   TesteSavareSisInfo was successfully deployed in 1.360 milliseconds.
Informações:   JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://TI:8686/jndi/rmi://TI:8686/jmxrmi
Informações:   Listening to REST requests at context: /management/domain.
Informações:   Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@40368a46 as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@621f89b8.
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   visiting unvisited references
Informações:   Inicializando Mojarra 2.2.12 ( 20150720-0848 ://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) para o contexto ''
Informações:   Loading application [__admingui] at [/]
Informações:   Loading application __admingui done in 2.591 ms
Grave:   MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList.

The other methods work, only this one that should return an Arraylist does not work. Below goes the class method that returns the Arraylist:

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/")
public List<String> listChamados() {
    List<String> lista = new ArrayList<String>();
    try {

        lista.add("Verificar a diferença de preço entre a parcela e a fatura.");
        lista.add("Não esqueça de buscar todos os erros.");
    } catch (Exception ex) {
        lista.add(ex.getMessage());
    }
    return  lista;
}

Below is the dependencies within the file pom.xml:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core"  -->
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.23.2</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

1 answer

0


Try to change the MediaType of your @Produces.

From what I understand he is not able to parse his List for Plain Text, try to use the MediaType correct for json.

MediaType.APPLICATION_JSON or MediaType.APPLICATION_JSON_TYPE

  • I’ve tried this before, I’ve changed the MediaType before to MediaType.APPLICATION_JSON and the same error persists.

  • Trade for MediaType json and put the error stack in the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.