0

All my other Injections are working but it's not working with gson. I have the feeling it's because it's an external package, but I can't resolve the issue. Here are my relevant files:

Producer:

public class GsonFactory {
    @Produces
    public Gson createGson(){return new GsonBuilder().createGson();}
}

injectionpoint:

@ApplicationScoped
public class SoundcloudAPIWrapper implements Serializable{

    @Inject
    private Gson gson;

    public SoundcloudAPIWrapper() {}

    ...

}

Beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
    bean-discovery-mode="all" version="2.0">
</beans>
Lukas
  • 169
  • 1
  • 3
  • 8
  • Can you confirm that `@Produces` is not `@javax.ws.rs.Produces`, but rather, `@javax.enterprise.inject.Produces` – maress Jul 11 '18 at 12:11
  • So it works if you replace Gson with String? – Kukeltje Jul 11 '18 at 14:29
  • thank you it was the enterprise `@javax.enterprise.inject.Produces` . now it's working. But why doesn't `@javax.ws.rs.Produces` work? All my other factories use the `ws.rs` . I'm very new to javaee, so an explanation would be great :) – Lukas Jul 12 '18 at 09:20

1 Answers1

1

like @maress pointed out in the comment, I needed to replace @javax.ws.rs.Produces with @javax.enterprise.inject.Produces. It's now working

Lukas
  • 169
  • 1
  • 3
  • 8