Pavel Pscheidl created WFLY-8584:
------------------------------------
Summary: Unite Jackson behavior with other application servers for JAX-RS
client
Key: WFLY-8584
URL:
https://issues.jboss.org/browse/WFLY-8584
Project: WildFly
Issue Type: Feature Request
Reporter: Pavel Pscheidl
Assignee: Jason Greene
Priority: Optional
Currently, WildFly's behaviour is not aligned with with other application servers when
JSON is deserialized into POJOs.
h3. Unrecognized properties
UnrecognizedPropertyException - The property is in the JSON, but not in the POJO. Other
application servers ignore such properties
{code:java}
public class SomeDTO{
private String property1;
//Getters and setters
}
{code}
{code:json}
{
"property1": "This one will not cause any troubles",
"property2": "This one causes UnrecognizedPropertyException istead of being
ignored"
}
{code}
To fix this behavior, provided dependency on arbitraty Jackson version must be present in
the project and @JsonIgnoreProperties annotation must be used.
{code:java}
@JsonIgnoreProperties(ignoreUnknown = true)
public class SomeDTO {
private String property1;
//Getters and setters
}
{code}
Programs without @JsonIgnoreProperties annotation are very fragile in production (the API
contract may change (one moje property added) and the whole client goes down.
h3. Property naming
Property naming - POJO attribute naming are what matters elsewhere. In WildFly,
@JsonProperty annotation must be used to tell Jackson the correct name of the POJO, since
all the attribute names are for some reason converted into lower case. This also results
in UnrecognizedPropertyException.
This code will not work
{code:java}
public class Rates {
private BigDecimal AUD;
}
{code}
for this JSON:
{code:json}
{
"AUD": 1.334523
}
{code}
The resulting error is:
{code:text}
Unrecognized field "AUD" (class entity.Rates), not marked as ignorable (31 known
properties: "aud",....
{code}
However, when @JsonProperty annotation is used on the field, things suddenly work:
{code:java}
public class Rates {
@JsonProperty("AUD")
private BigDecimal AUD;
}
{code}
Jackson annotations provided dependency must be used almost every time to ensure
application stability in production. This is less problematic nowadays, when near every
application server contains Jackson. When Java EE 8 comes, this will be even more
controversial:
{code:xml}
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.6</version>
<scope>provided</scope>
</dependency>
{code}
h3. Behavior of other application servers
There is a sample JAX-RS client/sever application [on
GitHub|https://github.com/Pscheidl/jax-rs-application-server-test]. When deployed without
Jackson annotations, it works perfectly in:
# Glassfish 4
# Payara 171 /obviously, should be the same as Glassfish/
# TomEE
# Websphere Liberty
Other AS were not tested.
Please note, there is also the problem with Resteasy not creating HTTP pools, causing
problems when calling WebTarget conncurrently. The sample application may cause errors in
WildFly when called concurrently.
h3. Proposal summary
I propose adopting behavior of other application servers - no Jackson annotations required
by default. Missing properties being ignored by default, as well as correcting the
property name resolution.
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)