[
https://issues.jboss.org/browse/WFLY-8584?page=com.atlassian.jira.plugin....
]
Marek Kopecký commented on WFLY-8584:
-------------------------------------
*Unrecognized properties*
* WF11
** 400: Unrecognized field "b" (class com.resteasy.test.CustomObject), not
marked as ignorable
* WF Master Jackson:
** ./standalone.sh -Dresteasy.preferJacksonOverJsonB=true
** 400: Unrecognized field "b" (class com.resteasy.test.CustomObject), not
marked as ignorable
* WF Master JSON-B
** 200
* Payara with Jersey (reference jax-rs implementation)
** 200
JSON-B behaviour is the same on Payara and WF. And we probably shouldn't change
default Jackson behaviour because of backward compatibility.
*Property naming (ABCD, getABCD, setABCD)*
* WF11
** {"abcd":"ABCD"}
* WF Master Jackson
** {"abcd":"ABCD"}
* WF Master JSON-B
** {"ABCD":"ABCD"}
* Payara with Jersey (reference jax-rs implementation)
** {"ABCD":"ABCD"}
JSON-B behaviour is the same on Payara and WF. And we probably shouldn't change
default Jackson behaviour because of backward compatibility.
*Pool issue*
* This looks like a bug, but github application doesn't work any more, because fixer
API is changed.
* Anyway, I believe I'm able to reproduce this issue on WF11
* I'm not able to reproduce this issue on WF master
{code:java}
@POST
@Path("test")
public String test(String data) {
return "response" + data;
}
private static Client client;
static {
client = ClientBuilder.newClient();
}
private static WebTarget target =
client.target("http://127.0.0.1:8080/jaxrs-wf/hello/test");
@GET
@Path("client")
public String client() throws ExecutionException, InterruptedException {
final int AVAILABLE_THREADS = 100;
final int ITERATION_OF_EACH_THREAD = 100;
ForkJoinPool forkJoinPool = new ForkJoinPool(AVAILABLE_THREADS);
forkJoinPool.submit(() ->
//parallel task here, for example
IntStream.range(1, AVAILABLE_THREADS).parallel().forEach(i -> {
for (int j = 0; j < ITERATION_OF_EACH_THREAD; j++) {
logger.info("Thread " + i + " start request
" + j);
String data = i + " " + j;
String message =
target.request().buildPost(Entity.text(data)).invoke(String.class);
if (!message.equals("response" + data)) {
throw new RuntimeException(data);
}
logger.info("Thread " + i + "'s request
" + j + " is done");
}
}
)
).get();
return "ok";
}
{code}
----
[~ron_sigal]: WDYT? What about to close this jira? [~pavelpscheidl]: Any thoughts?
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
Components: REST
Reporter: Pavel Pscheidl
Assignee: Weinan Li
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.12.1#712002)