How to replace jackson for moxy on payara 5





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







4















I read a lot about how to replace jackson for moxy on payara 5 but never achieve a good solution, so I create a small project and hope that someone can help me.



pom.xml



<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>${version.javaee}</version>
<scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>

<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<type>pom</type>
<version>1.4</version>
</dependency>
<dependencies>


App.java



import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import org.glassfish.jersey.jackson.JacksonFeature;

@ApplicationPath("/api")
public class App extends Application {

@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
resources.add(JacksonFeature.class);

resources.add(SimpleService.class);
return resources;
}

}


SimpleService.java



@Path("sample")
public class SimpleService {

@Path("greet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity doGreet2() {
PojoEntity pojoEntity = new PojoEntity();
pojoEntity.setTeste1("TesteValue1");
pojoEntity.setTeste2("TesteValue2");
return pojoEntity;
}
}


PojoEntity.java



public class PojoEntity {


private String teste1;

@JsonProperty("differentName")
private String teste2;

//getters and setters
}


After deploy this micro application into payara 5 and request the endpoint http://localhost:8080/micro-sample/api/sample/greet2 the result is (as expected):



{"teste1":"TesteValue1","differentName":"TesteValue2"}


Payara is using Jackson instead of moxy. :) Nice!!!



==============================================



My problem is when I use microprofile to reach my own endpoint:



SimpleServiceMicroprofileApi.java



import javax.enterprise.context.Dependent;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@Dependent
@RegisterRestClient
@Produces(MediaType.APPLICATION_JSON)
public interface SimpleServiceMicroprofileApi {

@Path("api/sample/greet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity recallGreet2();
}


MicroService.java



    package fish.payara.micro.sample;

import java.net.MalformedURLException;
import java.net.URL;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.RestClientBuilder;

@Path("micro")
public class MicroService {

@Path("recallGreet2")
@GET
@Produces(MediaType.APPLICATION_JSON)
public PojoEntity recallGreet2() throws MalformedURLException {
PojoEntity pojoEntity = new PojoEntity();
pojoEntity.setTeste1("LOL");
pojoEntity.setTeste2("LOL2");

URL apiUrl = new URL("http://localhost:8080/micro-sample");
SimpleServiceMicroprofileApi playlistSvc = RestClientBuilder.newBuilder().baseUrl(apiUrl)
.build(SimpleServiceMicroprofileApi.class);

return playlistSvc.recallGreet2();
}
}


And add this line on App.java on getClasses method:



resources.add(MicroService.class);


After the redeploy with this modifications we can access http://localhost:8080/micro-sample/api/micro/recallGreet2 and the result is:



{"teste1":"LOL","differentName":null}


Apparently microprofile keeps using moxy and ignore PojoEntity property "differentName".



Anyone know a way to completely replace moxy for jackson in this example?



This project is available here to make it possible to test this situation. :)



Payara version: 5.183



Thanks in advance.










share|improve this question





























    4















    I read a lot about how to replace jackson for moxy on payara 5 but never achieve a good solution, so I create a small project and hope that someone can help me.



    pom.xml



    <dependencies>
    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>${version.javaee}</version>
    <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
    <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.27</version>
    </dependency>

    <dependency>
    <groupId>org.eclipse.microprofile</groupId>
    <artifactId>microprofile</artifactId>
    <type>pom</type>
    <version>1.4</version>
    </dependency>
    <dependencies>


    App.java



    import javax.ws.rs.ApplicationPath;
    import javax.ws.rs.core.Application;

    import org.glassfish.jersey.jackson.JacksonFeature;

    @ApplicationPath("/api")
    public class App extends Application {

    @Override
    public Set<Class<?>> getClasses() {
    Set<Class<?>> resources = new java.util.HashSet<>();
    resources.add(JacksonFeature.class);

    resources.add(SimpleService.class);
    return resources;
    }

    }


    SimpleService.java



    @Path("sample")
    public class SimpleService {

    @Path("greet2")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public PojoEntity doGreet2() {
    PojoEntity pojoEntity = new PojoEntity();
    pojoEntity.setTeste1("TesteValue1");
    pojoEntity.setTeste2("TesteValue2");
    return pojoEntity;
    }
    }


    PojoEntity.java



    public class PojoEntity {


    private String teste1;

    @JsonProperty("differentName")
    private String teste2;

    //getters and setters
    }


    After deploy this micro application into payara 5 and request the endpoint http://localhost:8080/micro-sample/api/sample/greet2 the result is (as expected):



    {"teste1":"TesteValue1","differentName":"TesteValue2"}


    Payara is using Jackson instead of moxy. :) Nice!!!



    ==============================================



    My problem is when I use microprofile to reach my own endpoint:



    SimpleServiceMicroprofileApi.java



    import javax.enterprise.context.Dependent;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;

    import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

    @Dependent
    @RegisterRestClient
    @Produces(MediaType.APPLICATION_JSON)
    public interface SimpleServiceMicroprofileApi {

    @Path("api/sample/greet2")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public PojoEntity recallGreet2();
    }


    MicroService.java



        package fish.payara.micro.sample;

    import java.net.MalformedURLException;
    import java.net.URL;

    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;

    import org.eclipse.microprofile.rest.client.RestClientBuilder;

    @Path("micro")
    public class MicroService {

    @Path("recallGreet2")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public PojoEntity recallGreet2() throws MalformedURLException {
    PojoEntity pojoEntity = new PojoEntity();
    pojoEntity.setTeste1("LOL");
    pojoEntity.setTeste2("LOL2");

    URL apiUrl = new URL("http://localhost:8080/micro-sample");
    SimpleServiceMicroprofileApi playlistSvc = RestClientBuilder.newBuilder().baseUrl(apiUrl)
    .build(SimpleServiceMicroprofileApi.class);

    return playlistSvc.recallGreet2();
    }
    }


    And add this line on App.java on getClasses method:



    resources.add(MicroService.class);


    After the redeploy with this modifications we can access http://localhost:8080/micro-sample/api/micro/recallGreet2 and the result is:



    {"teste1":"LOL","differentName":null}


    Apparently microprofile keeps using moxy and ignore PojoEntity property "differentName".



    Anyone know a way to completely replace moxy for jackson in this example?



    This project is available here to make it possible to test this situation. :)



    Payara version: 5.183



    Thanks in advance.










    share|improve this question

























      4












      4








      4








      I read a lot about how to replace jackson for moxy on payara 5 but never achieve a good solution, so I create a small project and hope that someone can help me.



      pom.xml



      <dependencies>
      <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>${version.javaee}</version>
      <scope>provided</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
      <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
      <version>2.27</version>
      </dependency>

      <dependency>
      <groupId>org.eclipse.microprofile</groupId>
      <artifactId>microprofile</artifactId>
      <type>pom</type>
      <version>1.4</version>
      </dependency>
      <dependencies>


      App.java



      import javax.ws.rs.ApplicationPath;
      import javax.ws.rs.core.Application;

      import org.glassfish.jersey.jackson.JacksonFeature;

      @ApplicationPath("/api")
      public class App extends Application {

      @Override
      public Set<Class<?>> getClasses() {
      Set<Class<?>> resources = new java.util.HashSet<>();
      resources.add(JacksonFeature.class);

      resources.add(SimpleService.class);
      return resources;
      }

      }


      SimpleService.java



      @Path("sample")
      public class SimpleService {

      @Path("greet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity doGreet2() {
      PojoEntity pojoEntity = new PojoEntity();
      pojoEntity.setTeste1("TesteValue1");
      pojoEntity.setTeste2("TesteValue2");
      return pojoEntity;
      }
      }


      PojoEntity.java



      public class PojoEntity {


      private String teste1;

      @JsonProperty("differentName")
      private String teste2;

      //getters and setters
      }


      After deploy this micro application into payara 5 and request the endpoint http://localhost:8080/micro-sample/api/sample/greet2 the result is (as expected):



      {"teste1":"TesteValue1","differentName":"TesteValue2"}


      Payara is using Jackson instead of moxy. :) Nice!!!



      ==============================================



      My problem is when I use microprofile to reach my own endpoint:



      SimpleServiceMicroprofileApi.java



      import javax.enterprise.context.Dependent;
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;

      import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

      @Dependent
      @RegisterRestClient
      @Produces(MediaType.APPLICATION_JSON)
      public interface SimpleServiceMicroprofileApi {

      @Path("api/sample/greet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity recallGreet2();
      }


      MicroService.java



          package fish.payara.micro.sample;

      import java.net.MalformedURLException;
      import java.net.URL;

      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;

      import org.eclipse.microprofile.rest.client.RestClientBuilder;

      @Path("micro")
      public class MicroService {

      @Path("recallGreet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity recallGreet2() throws MalformedURLException {
      PojoEntity pojoEntity = new PojoEntity();
      pojoEntity.setTeste1("LOL");
      pojoEntity.setTeste2("LOL2");

      URL apiUrl = new URL("http://localhost:8080/micro-sample");
      SimpleServiceMicroprofileApi playlistSvc = RestClientBuilder.newBuilder().baseUrl(apiUrl)
      .build(SimpleServiceMicroprofileApi.class);

      return playlistSvc.recallGreet2();
      }
      }


      And add this line on App.java on getClasses method:



      resources.add(MicroService.class);


      After the redeploy with this modifications we can access http://localhost:8080/micro-sample/api/micro/recallGreet2 and the result is:



      {"teste1":"LOL","differentName":null}


      Apparently microprofile keeps using moxy and ignore PojoEntity property "differentName".



      Anyone know a way to completely replace moxy for jackson in this example?



      This project is available here to make it possible to test this situation. :)



      Payara version: 5.183



      Thanks in advance.










      share|improve this question














      I read a lot about how to replace jackson for moxy on payara 5 but never achieve a good solution, so I create a small project and hope that someone can help me.



      pom.xml



      <dependencies>
      <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>${version.javaee}</version>
      <scope>provided</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
      <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
      <version>2.27</version>
      </dependency>

      <dependency>
      <groupId>org.eclipse.microprofile</groupId>
      <artifactId>microprofile</artifactId>
      <type>pom</type>
      <version>1.4</version>
      </dependency>
      <dependencies>


      App.java



      import javax.ws.rs.ApplicationPath;
      import javax.ws.rs.core.Application;

      import org.glassfish.jersey.jackson.JacksonFeature;

      @ApplicationPath("/api")
      public class App extends Application {

      @Override
      public Set<Class<?>> getClasses() {
      Set<Class<?>> resources = new java.util.HashSet<>();
      resources.add(JacksonFeature.class);

      resources.add(SimpleService.class);
      return resources;
      }

      }


      SimpleService.java



      @Path("sample")
      public class SimpleService {

      @Path("greet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity doGreet2() {
      PojoEntity pojoEntity = new PojoEntity();
      pojoEntity.setTeste1("TesteValue1");
      pojoEntity.setTeste2("TesteValue2");
      return pojoEntity;
      }
      }


      PojoEntity.java



      public class PojoEntity {


      private String teste1;

      @JsonProperty("differentName")
      private String teste2;

      //getters and setters
      }


      After deploy this micro application into payara 5 and request the endpoint http://localhost:8080/micro-sample/api/sample/greet2 the result is (as expected):



      {"teste1":"TesteValue1","differentName":"TesteValue2"}


      Payara is using Jackson instead of moxy. :) Nice!!!



      ==============================================



      My problem is when I use microprofile to reach my own endpoint:



      SimpleServiceMicroprofileApi.java



      import javax.enterprise.context.Dependent;
      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;

      import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

      @Dependent
      @RegisterRestClient
      @Produces(MediaType.APPLICATION_JSON)
      public interface SimpleServiceMicroprofileApi {

      @Path("api/sample/greet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity recallGreet2();
      }


      MicroService.java



          package fish.payara.micro.sample;

      import java.net.MalformedURLException;
      import java.net.URL;

      import javax.ws.rs.GET;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;

      import org.eclipse.microprofile.rest.client.RestClientBuilder;

      @Path("micro")
      public class MicroService {

      @Path("recallGreet2")
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public PojoEntity recallGreet2() throws MalformedURLException {
      PojoEntity pojoEntity = new PojoEntity();
      pojoEntity.setTeste1("LOL");
      pojoEntity.setTeste2("LOL2");

      URL apiUrl = new URL("http://localhost:8080/micro-sample");
      SimpleServiceMicroprofileApi playlistSvc = RestClientBuilder.newBuilder().baseUrl(apiUrl)
      .build(SimpleServiceMicroprofileApi.class);

      return playlistSvc.recallGreet2();
      }
      }


      And add this line on App.java on getClasses method:



      resources.add(MicroService.class);


      After the redeploy with this modifications we can access http://localhost:8080/micro-sample/api/micro/recallGreet2 and the result is:



      {"teste1":"LOL","differentName":null}


      Apparently microprofile keeps using moxy and ignore PojoEntity property "differentName".



      Anyone know a way to completely replace moxy for jackson in this example?



      This project is available here to make it possible to test this situation. :)



      Payara version: 5.183



      Thanks in advance.







      java jackson moxy payara microprofile






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 15:22









      tiagomistraltiagomistral

      484




      484
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You just need to register JacksonFeature on your SimpleServiceMicroprofileApi:



          @RegisterProvider(JacksonFeature.class)


          That should make it work;)






          share|improve this answer
























          • Thanks a lot :)

            – tiagomistral
            Nov 24 '18 at 15:30












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449234%2fhow-to-replace-jackson-for-moxy-on-payara-5%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You just need to register JacksonFeature on your SimpleServiceMicroprofileApi:



          @RegisterProvider(JacksonFeature.class)


          That should make it work;)






          share|improve this answer
























          • Thanks a lot :)

            – tiagomistral
            Nov 24 '18 at 15:30
















          1














          You just need to register JacksonFeature on your SimpleServiceMicroprofileApi:



          @RegisterProvider(JacksonFeature.class)


          That should make it work;)






          share|improve this answer
























          • Thanks a lot :)

            – tiagomistral
            Nov 24 '18 at 15:30














          1












          1








          1







          You just need to register JacksonFeature on your SimpleServiceMicroprofileApi:



          @RegisterProvider(JacksonFeature.class)


          That should make it work;)






          share|improve this answer













          You just need to register JacksonFeature on your SimpleServiceMicroprofileApi:



          @RegisterProvider(JacksonFeature.class)


          That should make it work;)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 17:04









          yougoyougo

          261




          261













          • Thanks a lot :)

            – tiagomistral
            Nov 24 '18 at 15:30



















          • Thanks a lot :)

            – tiagomistral
            Nov 24 '18 at 15:30

















          Thanks a lot :)

          – tiagomistral
          Nov 24 '18 at 15:30





          Thanks a lot :)

          – tiagomistral
          Nov 24 '18 at 15:30




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449234%2fhow-to-replace-jackson-for-moxy-on-payara-5%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]