aspose file tools*
The moose likes Spring and the fly likes Issue when implementing collection on grid object using Jackson in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Issue when implementing collection on grid object using Jackson in Spring" Watch "Issue when implementing collection on grid object using Jackson in Spring" New topic
Author

Issue when implementing collection on grid object using Jackson in Spring

Sarin Thanissery
Greenhorn

Joined: Sep 10, 2010
Posts: 3
we are using spring jackson conversion for populating the jq grid(josn created using Jackson), we are using an dto object to populate the grid. But when the dto object implements collection, we are experiencing a strange behaviour. Only the list are returned and it ignores other properties like count, pageSize etc. Please have a look at the dto class,

the TestDto class is,
public class TestDto<T> implements Serializable, Collection<T> {

protected int count;
protected int pageSize;
protected Collection<T> rows;
public TestDto(int count, int pageSize, Collection<T> rows) {
this.rows= rows;
this.count = count;
this.pageSize = pageSize;
}

public int getPageSize() {
return pageSize;
}

public int getCount() {
return count;
}

public Collection<T> getRows() {
return rows;
}

/** overrided methods **/
}


In the client side, I am getting only the list of datas. Other properties(count, pagesize) are ignored, when I removed the implements collection part, all properties are available on client side. But we need to implement the collection part

Could you please help me to fix the issue, is there any way to fix the issue using jacksonannotation

Regards ST
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17256
    
    6

You could try putting @JsonProperty on those two fields or getters and see if that forces the inclusion.

Just a question but why does it have to implement Collection?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sarin Thanissery
Greenhorn

Joined: Sep 10, 2010
Posts: 3
Hi Mark,

I have tried @JsonProperty option, but it didnt work, I got a clue why it is happening

I have an overrided method on implementing collection,

public Iterator<T> iterator() {
return rows.iterator();
}

This is causing problem, don't know Jackson has any dependency on method, any thoughts from your side?

Note: this class is used for pagination purpose, so I need to implement collection<t>

Thanks

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17256
    
    6

Sarin Thanissery wrote:Hi Mark,

I have tried @JsonProperty option, but it didnt work, I got a clue why it is happening

I have an overrided method on implementing collection,

public Iterator<T> iterator() {
return rows.iterator();
}

This is causing problem, don't know Jackson has any dependency on method, any thoughts from your side?

Note: this class is used for pagination purpose, so I need to implement collection<t>

Thanks



Sorry, but most Page type objects that I have seen/used don't implement Collection. It can hold a reference to a Collection, but not really a reason why it would need to implement Collection itself.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue when implementing collection on grid object using Jackson in Spring