eclipse-ee4j / eclipse-ee4j/yasson
How to Integrate with JPA
- Dominant language
- Java
- Stars
- 218
- Forks
- 109
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 9
Description
I've experience with JSON-B and Yasson on my Java EE 7 project and I'm tried to put the Jsonb annotations alongside with JPA annotations, for example something like this
```
@Entity
@Table("student")
@NamedQuery(name = Student.FIND_ALL, query = "select s from Student s")
public class Student {
public static final String FIND_ALL = "Student.findAll";
@JsonbTransient
private Long id;
@JsonbProperty("student-name")
private String name;
}
```
When I tried to request into my endpoint I'm encounter two problem:
1. It seems the JPA properties was also serialized by Jsonb, I got my response like below.
```
{
"serialVersionUID": null,
"_persistence_shouldRefreshFetchGroup": null,
"_persistence_session": null,
"_persistence_relationshipInfo": null,
"_persistence_primaryKey": null,
"_persistence_listener": null,
"_persistence_links": null,
"_persistence_href": null,
"_persistence_fetchGroup": null,
"_persistence_cacheKey": null,
"name": "Sukma",
"FIND_ALL": null
}
```
**How could I remove the JPA properties from my response?**
2. From response above I also found that my static variable `FIND_ALL` was serialized by Jsonb, I'm tried to hide it using `@JsonbTransient` but I received `Java.lang.NullPointerException`.
**Do I need to pay attention towards variable with keywords `static` or `final` when using Jsonb annotations, like on my `FIND_ALL` variable?**
Contributor guide
Assessment
This issue has not been assessed yet.