2

Upgrading from Wildfly-8.1.0.Final to Wildfly-17.0.1.Final

class Parent {
    String prop1;

    public Parent(String prop1) {
        this.prop1 = prop1;
    }
}

class Child extends Child {
    String prop2;

    public Child(String prop1, String prop2) {
        super(prop1);
        this.prop2 = prop2;
    }
}

In Controller Layer

public Parent getDetails() {
    return serviceImpl.getDetails();
}

In Service Layer

public Child getDetails() {
    return new Child("String1", "String2");
}

From Wildfly 8, we are getting

{
    "prop1": "String1",
    "prop2": "String2"
}

But from Wildfly 17, we are getting

{
    "prop1": "String1"
}

We thought it's maybe due to Jackson library, so we changed the jackson library version in pom.xml to 2.3.2 while running with Wildfly 17, but still it was coming in the same way

We tried with Jackson 2.9.8 with Wildfly 8 as well, but still WF8 returned both properties "prop1" and "prop2"

We are trying to find the root cause of this, does it have something related to internal implementation of WF17 or are we missing something else here ?

EDITED

We have tried one more thing : We tried to reproduce the issue with Jackson library on a standalone java code, and we are not able to reproduce this.

Although its still coming with Wildfly 8 or Wildfly 17 when ran with above Jackson 2.6.0 versions, till 2.5.5 this is not coming.

RobC
  • 22,977
  • 20
  • 73
  • 80

3 Answers3

0

When you switched to an alternate Jackson version, did you exclude Jackson regular/default jars, so that your jars will take precedence ?

This can be done by adding a file named "jboss-deployment-structure.xml" (to put under WEB-INF folder) and whose content is - for instance:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <deployment>
        <exclusions>        
            <module name="com.fasterxml.jackson.core.jackson-databind"/>
            <module name="com.fasterxml.jackson.core.jackson-core"/>
            <module name="com.fasterxml.jackson.core.jackson-annotations"/>
            <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider"/>

You can find the various Jackson modules here: .../wildfly-17.0.1.Final/modules/system/layers/base/com/fasterxml/jackson

Hope this helps

TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17
0

You could also try to annotate your super class (eg Parent) with Jackson annotations in order to register Child as subclass.

@JsonTypeInfo(use=Id.NAME)
@JsonSubTypes({
        @JsonSubTypes.Type(value=Child.class, name="child"),        
})

Be careful as this will NOT be sufficient if you need to deserialize your json. Have a look here: http://federico.defaveri.org/2016/11/20/handling-polymorphism-with-jackson/

TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17
0

Issue Fixed: It was due to spring version that we were using, 4.2.0 (this version of spring does not support Jackson 2.6+ versions) That's why it was coming from Jackson 2.6.0.

It's a bug in spring fixed in Spring 4.2.1

https://github.com/spring-projects/spring-framework/issues/18008

https://jira.spring.io/browse/SPR-13429?redirect=false

Now its working with Spring 4.2.1 with Jackson 2.9.9 as well.