I have a transient field in my POJO which I want to serialize but currently the field is not visible in JSON response
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 .
The Field is not at all visible in the JSON response
This is the field : com.javastreets.ee.microprofile.entities.ResponseDO#data
Please access this URL :
http://localhost:8080/micro/api/books/readuserallwebservicedata
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>
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
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