resthub / resthub-spring-stack

RESThub Spring stack
http://resthub.org/spring-stack.html
Other
121 stars 66 forks source link

Issue #154 : custom JsonView annotations support #159

Closed sdeleuze closed 11 years ago

bclozel commented 11 years ago

@bmeurant is preparing a PR regarding @Transactional issues. Actually, the default strategy is required=true and readOnly=false; we were kind of used to readOnly=true because of GenericService in RESThub 1.x.

Could you delete some parts of your PR? I'll point the exact lines to make this easier.

sdeleuze commented 11 years ago

Additional informations, this functionality should allow to fix serialization issues for children-parent when we were using previously @JsonIgnore or @JsonBackReference. Another use case is that it allows us to use again lazy loading + OpenSessionInView filter.

Here is a code sample showing these 2 improvements (not tested yet, so there may be issues) :


public class Library {
    @JsonView(BookListView.class)
     private List<Book> books;
}

public class Book {

    @ManyToOne(fetch = FetchType.LAZY)
     private Library library;

    @JsonView(BookListView.class)
     private String name;

    @OneToMany(fetch = FetchType.LAZY)
    private List<Page> pages;
}

@RequestMapping("books")
@ResponseView(BookListView.class)
public @ResponseBody List<Book> getBooks()
{
    return data;
}

@RequestMapping("{id}")
public @ResponseBody Book getBook(@PathVariable("id") Integer id)
{
    return data.get(id - 1);
}
bclozel commented 11 years ago

great!