2

I am developing web application with spring mvc and Data sent to client in json format. I want to have some views of same model object thus i can return only needed data ,not more.Jackson library @JsonIgnore , @JsonIgnoreProperties not suit this .Jackson library have also @JsonView and @JsonFilter annotations but they didnt help too.How can handle this problem.For example ,i will need possibleTarget list in some pages of UI and sometimes dont need.This is the same question but answer not help me

 @Entity
    public class Warrant implements Serializable {

          @Column
          String name;

        @JsonIgnore
        @ManyToOne
        private User owner;

        @Column
        private String value;

        @OneToMany(mappedBy = "warrant", targetEntity = com.endersys.lims.model.Target.class)
        private List<Target> possibleTargets;

       .....
    }
Community
  • 1
  • 1
ayengin
  • 1,606
  • 1
  • 22
  • 47

1 Answers1

2

You're mixing application layers. Don't send entities from your persistence layer to the view. Use Transfer Objects, that way you can easily control what you show the world.

You might want to use a framework like Dozer to automate data transfer between layers.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • Dozer rocks! :-) Agree completely, mixing JSON serialization with ORM mapping in one place. – Peter Perháč Nov 21 '11 at 20:46
  • @Peter Perhac, I want to serialize my model object to json with needed fields and .I dont want to create java classes for only group properties .Can I do that with annotation like this project http://www.devx.com/Java/Article/42946/1954 generate getter setter at compile time – ayengin Nov 22 '11 at 15:00
  • Only way i think writing a @view(name={proper1,proper3},name2={property4} ) annotation and generate java classes ,specified by name and fields and return this generated classes from spring controller .Is this possible.Or I have to create java classes for every view manually. – ayengin Nov 22 '11 at 15:04
  • 1
    Dozer framework is usefull,But i dont want to create java class for just mapping .Can i handle this with annotations. – ayengin Nov 23 '11 at 12:08