Payara: JDK11 Transient field is not serialized by Jersey

Created on 21 Aug 2020  路  6Comments  路  Source: payara/Payara

# Description #

I have a transient field in my POJO which I want to serialize but currently the field is not visible in JSON response

Expected Outcome

The field should be visible because I have not annotated it with JSON Ignore .

if I remove the transient field then the field is visible in the JSON response .

Current Outcome

The Field is not at all visible in the JSON response

Steps to reproduce (Only for bug reports)

This is the field : com.javastreets.ee.microprofile.entities.ResponseDO#data

Please access this URL :
http://localhost:8080/micro/api/books/readuserallwebservicedata

Samples

import java.util.ArrayList;
import java.util.List;

@XmlRootElement
@XmlSeeAlso({AllWebServiceDataDO.class})
public class ResponseDO<T extends Object>  extends AbstractDO implements Serializable {

    private static final long serialVersionUID = 1L;

    **private  transient T data = null;**
    private List<String> infos = new ArrayList<>();
    private List<String> warnings = new ArrayList<>();
    private List<String> errors = new ArrayList<>();

Attached the simple example application that uses org.eclipse.microprofile.microprofile version 3.3

<dependency>
            <groupId>org.eclipse.microprofile</groupId>
            <artifactId>microprofile</artifactId>
            <version>3.3</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

Environment

  • Payara Version: 5.2020.3 #badassfish (build 517)
  • Edition: Web
  • JDK Version: openjdk version "11.0.8" 2020-07-14 LTS
  • Operating System: Windows
  • Database: NA
Pending

Most helpful comment

JSR-353 is JSON-P. Yasson is JSON-B. So it are 2 different specifications.

Best is to remove Genson as Payara has its own JSON-P library on board and probably conflict.

If needed, create a reproducer that follow the SSCCE rules: http://www.sscce.org/ and open a new issue.

regards
Rudy

All 6 comments

Hi,

Can you indicate why the field needs to be transient? If it is for JPA reasons, you can annotate with @javax.persistence.Transient.

Otherwise we have to dig deeper into the JSON-B implementation.

Regards
Rudy

HI @rdebusscher ,

The reason why this is transient is unknown to me as We got this project from another Organization , now , we are migrating this to payara 5 and JDK11.

but this not JPA Entity , this class is used as a DTO to send response to user .

It would be great if you can initiate the deeper analysis meanwhile If I find anything I will update here.

Thank you.

Hi ,

I have looked up the JSON-B specification, and in fact the implementation must ignore transient fields

Section 3.7.1 of https://download.oracle.com/otndocs/jcp/json_b-1-pr-spec/index.html

Transient and static fields MUST be ignored during serialization operation.

So it is the desired behaviour.

I have also verified it on JDK 8, and there it is also ignored. Since it is not an JPA entity but a DTO to transfer the data to the client via REST, I propose to remove the transient keyword.

Regards
Rudy

Thank you so much , one clarification pls,

before, the project is using payara 4 and https://github.com/owlike/genson for json creation in that case genson was serializing the transient field also.

now once I move to payara 5 with genson I was getting an Exception

[2020-08-21T19:00:58.239+0530] [] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=76 _ThreadName=http-thread-pool::http-listener(2)] [timeMillis: 1598016658239] [levelValue: 900] [[
  StandardWrapperValve[Jersey Web Application]: Servlet.service() for servlet Jersey Web Application threw exception
java.lang.AbstractMethodError: Receiver class com.owlike.genson.ext.**jsr353**.GensonJsonGenerator does not define or inherit an implementation of the resolved method 'abstract javax.json.stream.J
sonGenerator writeKey(java.lang.String)' of interface javax.json.stream.JsonGenerator.
        at org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:105)
        at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:69)
        at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:107)
        at org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:146)
        at org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:74)

I upgraded genson to latest version still the same Issue.

My doubt here is : is Genson not following the Specification ?( I see JSR353 in the LOG ) .

Thanks again

kindly check my above comment

JSR-353 is JSON-P. Yasson is JSON-B. So it are 2 different specifications.

Best is to remove Genson as Payara has its own JSON-P library on board and probably conflict.

If needed, create a reproducer that follow the SSCCE rules: http://www.sscce.org/ and open a new issue.

regards
Rudy

Was this page helpful?
0 / 5 - 0 ratings