Using transient for both Gson and Hibernate in the same file
up vote
0
down vote
favorite
I have entity that I need some of the fields not to be persisted and some of the fields not to be serialized.
I am using the @Transient on some of the fields but when I want to mark transient for the Gson. The issue is that hibernate picks it up and also not persist it since its also a keyword in Hibernate .
I use Hibernate-jpa-2.1-api javax.persistence.Transient
I am trying prevent addresses
from being serialized and getDefaultAddress
should not be saved.
Code:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
Any solution?
java hibernate gson transient
add a comment |
up vote
0
down vote
favorite
I have entity that I need some of the fields not to be persisted and some of the fields not to be serialized.
I am using the @Transient on some of the fields but when I want to mark transient for the Gson. The issue is that hibernate picks it up and also not persist it since its also a keyword in Hibernate .
I use Hibernate-jpa-2.1-api javax.persistence.Transient
I am trying prevent addresses
from being serialized and getDefaultAddress
should not be saved.
Code:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
Any solution?
java hibernate gson transient
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have entity that I need some of the fields not to be persisted and some of the fields not to be serialized.
I am using the @Transient on some of the fields but when I want to mark transient for the Gson. The issue is that hibernate picks it up and also not persist it since its also a keyword in Hibernate .
I use Hibernate-jpa-2.1-api javax.persistence.Transient
I am trying prevent addresses
from being serialized and getDefaultAddress
should not be saved.
Code:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
Any solution?
java hibernate gson transient
I have entity that I need some of the fields not to be persisted and some of the fields not to be serialized.
I am using the @Transient on some of the fields but when I want to mark transient for the Gson. The issue is that hibernate picks it up and also not persist it since its also a keyword in Hibernate .
I use Hibernate-jpa-2.1-api javax.persistence.Transient
I am trying prevent addresses
from being serialized and getDefaultAddress
should not be saved.
Code:
@Entity
@Table(name="Business")
public class Business{
@OneToMany(mappedBy="business")
private transient List<Phone> addresses;
@Transient
public Phone getDefaultPhone() {
return phones.get(0);
}
}
Any solution?
java hibernate gson transient
java hibernate gson transient
edited Jun 14 '15 at 10:31
asked Jun 14 '15 at 3:22
special0ne
2,520135595
2,520135595
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
You can use @Expose
@Expose(serialize = false)
@OneToMany(cascade=CascadeType.ALL, mappedBy="business")
private List<Address> addresses;
In order to be able to work with this annotation,
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Source : http://www.javacreed.com/gson-annotations-example/
add a comment |
up vote
0
down vote
I am using Play Framework's implementation of JPA, and Gson.
I got it working with JPA class as follows, which involved constructing the embedded object dynamically before marshalling to json, and no changes were required for the GSON builder, as modifying GSONBuilder will change the strategy globally for other classes as well.
public class DBServiceDefinition {
@Transient
@Expose(serialize = true)
@SerializedName("serviceStatus")
public ServiceDefinitionStatus status = new
ServiceDefinitionStatus(201,"SUCCESS","","Test");
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use @Expose
@Expose(serialize = false)
@OneToMany(cascade=CascadeType.ALL, mappedBy="business")
private List<Address> addresses;
In order to be able to work with this annotation,
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Source : http://www.javacreed.com/gson-annotations-example/
add a comment |
up vote
0
down vote
You can use @Expose
@Expose(serialize = false)
@OneToMany(cascade=CascadeType.ALL, mappedBy="business")
private List<Address> addresses;
In order to be able to work with this annotation,
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Source : http://www.javacreed.com/gson-annotations-example/
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use @Expose
@Expose(serialize = false)
@OneToMany(cascade=CascadeType.ALL, mappedBy="business")
private List<Address> addresses;
In order to be able to work with this annotation,
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Source : http://www.javacreed.com/gson-annotations-example/
You can use @Expose
@Expose(serialize = false)
@OneToMany(cascade=CascadeType.ALL, mappedBy="business")
private List<Address> addresses;
In order to be able to work with this annotation,
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Source : http://www.javacreed.com/gson-annotations-example/
answered Jun 14 '15 at 3:59
Darshan Patel
1,91611529
1,91611529
add a comment |
add a comment |
up vote
0
down vote
I am using Play Framework's implementation of JPA, and Gson.
I got it working with JPA class as follows, which involved constructing the embedded object dynamically before marshalling to json, and no changes were required for the GSON builder, as modifying GSONBuilder will change the strategy globally for other classes as well.
public class DBServiceDefinition {
@Transient
@Expose(serialize = true)
@SerializedName("serviceStatus")
public ServiceDefinitionStatus status = new
ServiceDefinitionStatus(201,"SUCCESS","","Test");
}
add a comment |
up vote
0
down vote
I am using Play Framework's implementation of JPA, and Gson.
I got it working with JPA class as follows, which involved constructing the embedded object dynamically before marshalling to json, and no changes were required for the GSON builder, as modifying GSONBuilder will change the strategy globally for other classes as well.
public class DBServiceDefinition {
@Transient
@Expose(serialize = true)
@SerializedName("serviceStatus")
public ServiceDefinitionStatus status = new
ServiceDefinitionStatus(201,"SUCCESS","","Test");
}
add a comment |
up vote
0
down vote
up vote
0
down vote
I am using Play Framework's implementation of JPA, and Gson.
I got it working with JPA class as follows, which involved constructing the embedded object dynamically before marshalling to json, and no changes were required for the GSON builder, as modifying GSONBuilder will change the strategy globally for other classes as well.
public class DBServiceDefinition {
@Transient
@Expose(serialize = true)
@SerializedName("serviceStatus")
public ServiceDefinitionStatus status = new
ServiceDefinitionStatus(201,"SUCCESS","","Test");
}
I am using Play Framework's implementation of JPA, and Gson.
I got it working with JPA class as follows, which involved constructing the embedded object dynamically before marshalling to json, and no changes were required for the GSON builder, as modifying GSONBuilder will change the strategy globally for other classes as well.
public class DBServiceDefinition {
@Transient
@Expose(serialize = true)
@SerializedName("serviceStatus")
public ServiceDefinitionStatus status = new
ServiceDefinitionStatus(201,"SUCCESS","","Test");
}
edited Nov 21 at 7:27
piet.t
9,86863245
9,86863245
answered Aug 31 at 22:19
kanaparthikiran
35159
35159
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30825669%2fusing-transient-for-both-gson-and-hibernate-in-the-same-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown