Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-7403

Jsr310 and jdk8 fasterxml modules are not available from deployment without specific jboss-deployment-structure.xml

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 11.0.0.Alpha1
    • None
    • REST
    • None

    Description

      Description of problem:
      Jsr310 and jdk8 fasterxml modules are not available from deployment without specific jboss-deployment-structure.xml

      How reproducible:
      Always

      Steps to Reproduce:

      • This can be tested if "<module name="com.fasterxml.jackson.core.jackson-annotations"/>" is added to ./modules/system/layers/base/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/main/module.xml (see JBEAP-6673)
      1. Create end-point with data types and special jdk8 types and allows
            @GET
            @Path("entity/get/json")
            @Produces(MediaType.APPLICATION_JSON)
            public DatatypeObject getJson() {
                DatatypeObject per = new DatatypeObject();
                per.setString("someString");
                per.setDate(new Date());
                per.setDuration(Duration.ofSeconds(5, 6));
                per.setDayOfWeek(DayOfWeek.FRIDAY);
                per.setOptionalString1(Optional.of("info@example.com"));
                per.setOptionalString2(Optional.<String>empty());
                return per;
            }
        
      2. Implement custom ContextResolver in deployment. This code enables jsr310 and jdk8 fasterxml functionality. Example:
        @Provider
        @Produces( MediaType.APPLICATION_JSON )
        public class JacksonProducer implements ContextResolver<ObjectMapper> {
        
            private final ObjectMapper json;
        
            public JacksonProducer() throws Exception {
                this.json = new ObjectMapper()
                                .findAndRegisterModules()
                                .configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false )
                                .configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
            }
        
            @Override
            public ObjectMapper getContext( Class<?> objectType ) {
                return json;
            }
        }
        
      3. Http request to REST end-point

      Actual results:

      {"string":"someString","optionalString1":{"present":true},"optionalString2":{"present":false},"duration":{"seconds":5,"zero":false,"negative":false,"units":["SECONDS","NANOS"],"nano":6},"date":"2016-10-27T13:02:11.991+0000"}
      

      Expected results:

      {"string":"someString","optionalString1":"info@example.com","optionalString2":null,"duration":"PT5.000000006S","date":"2016-10-27T13:01:03.923+0000"}
      

      Workaround:
      Expected results is returned if specific jboss-deployment-structure.xml file is used:

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-deployment-structure>
          <deployment>
              <dependencies>
                  <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" services="import"/>
                  <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" services="import"/>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      

      Attachments

        Issue Links

          Activity

            People

              sdouglas1@redhat.com Stuart Douglas
              sdouglas1@redhat.com Stuart Douglas
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: