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;

       .....
    }

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Dozer rocks! :-) Agree completely, mixing JSON serialization with ORM mapping in one place.
@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 devx.com/Java/Article/42946/1954 generate getter setter at compile time
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.
Dozer framework is usefull,But i dont want to create java class for just mapping .Can i handle this with annotations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.