java - Using transient for both Gson and Hibernate in the same file -


i have entity need of fields not persisted , of fields not serialized.

i using @transient on of fields when want mark transient gson. issue hibernate picks , not persist since keyword in hibernate .

i use hibernate-jpa-2.1-api javax.persistence.transient

i trying prevent addresses being serialized , getdefaultaddress should not 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?

you can use @expose

@expose(serialize = false) @onetomany(cascade=cascadetype.all, mappedby="business") private list<address> addresses; 

in order able work annotation,

final gsonbuilder builder = new gsonbuilder(); builder.excludefieldswithoutexposeannotation(); final gson gson = builder.create(); 

source : http://www.javacreed.com/gson-annotations-example/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -